map


map(fn, seq1, seq2, ...)
      

Apply the function fn to corresponding elements of the sequences seq1, seq2 ... and return a sequence of the resulting values. The sequences, if finite, must be of the same length. Fn should accept as many arguments as there are sequences, should return a single value, and should not mutate the sequences.

Examples:


map(abs, [1, -2, 3, -4, 5])
// [1, 2, 3, 4, 5]

map(`*`, [1, 2, 3, 4], [8, 7, 6, 5])
// [8, 14, 18, 20]

// mapping over infinite sequences:
function seq1(i) i:~seq1(i+1)
function seq2(i) i:~seq2(i+2)

let xs = seq1(10)
let ys = seq2(20)
let zs = map(add, xs, ys)
first(zs)
// 30
second(zs)
// 33
nth(10, zs)
// 60
      

Also see:

apply
for_each
for_all


Core Module Index | Contents