Why I cannot use a tuple in `map` directly?

You can use map, but the syntax is slightly different:

  • (i,j,v) -> v/(i*j) is an anonymous function with three arguments, but zip(x, y, z) creates three tuples which map then passes to the function.

To make the example work, either

  1. pass an anonymous function with a single argument destructuring into a three tuple:
    map(((i,j,v),) -> v/(i*j), zip([1,2],[10,20],[100,200]))
    
  2. or just pass all vectors as individual arguments to map (it will then call the function on three arguments instead of zipping them into three tuples):
    map((i,j,v) -> v/(i*j), [1,2],[10,20],[100,200])
    
8 Likes