Erlang comprehension list with two lists in sequence?

Is it possible to consistently use the list view for two lists, for items? Given A = [1,2,3] , B = [4,5,6] , we get C = [f(1, 4), f(2, 5), f(3, 6)] . In other words, a more direct / efficient way to do [f(U, V) || {U, V} = lists:zip(A, B)]. [f(U, V) || {U, V} = lists:zip(A, B)].

A similar question concerns binary files if A = <<1,2,3>> and B = <<4,5,6>> . This would be very useful if you need, for example, to use two binaries.

+4
source share
2 answers

This is currently not possible. This has already been proposed in EEP12 and EEP19 .

Your best bet is to implement your own recursive function for this.

+8
source

For this, the lists module already has a higher-order function, and it is called lists: zipwith / 3 . Your sample scenario will be implemented as follows:

 lists:zipwith(fun f/2, A, B). 
+1
source

All Articles