Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang list comprehension with two lists in sequence?

Is it possible to use list comprehension on two lists, item by item, in sequence? Given A = [1,2,3], B = [4,5,6], get some 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)].

Similar question goes to binaries, if given A = <<1,2,3>> and B = <<4,5,6>>. This would be very useful if you have to xor two binaries, for example.

like image 860
me2 Avatar asked Dec 17 '09 17:12

me2


1 Answers

It's not currently possible. It has already been proposed in EEP12 and EEP19.

Your best choice is to implement your own recursive function for that.

like image 182
Zed Avatar answered Oct 25 '22 02:10

Zed