ListFunctions2(A, B)ΒΆ

list.spad line 317

ListFunctions2 implements utility functions that operate on two kinds of lists, each with a possibly different type of element.

map: (A -> B, List A) -> List B
map(fn, u) applies fn to each element of list u and returns a new list with the results. For example map(square, [1, 2, 3]) = [1, 4, 9].
reduce: ((A, B) -> B, List A, B) -> B
reduce(fn, u, ident) successively uses the binary function fn on the elements of list u and the result of previous applications. ident is returned if the u is empty. Note the order of application in the following examples: reduce(fn, [1, 2, 3], 0) = fn(3, fn(2, fn(1, 0))) and reduce(*, [2, 3], 1) = 3 * (2 * 1).
scan: ((A, B) -> B, List A, B) -> List B
scan(fn, u, ident) successively uses the binary function fn to reduce more and more of list u. ident is returned if the u is empty. The result is a list of the reductions at each step. See reduce for more information. Examples: scan(fn, [1, 2], 0) = [fn(2, fn(1, 0)), fn(1, 0)] and scan(*, [2, 3], 1) = [2 * 1, 3 * (2 * 1)].