array1.spad line 467 [edit on github]
This package provides tools for operating on one-dimensional arrays with unary and binary functions involving different underlying types.
map(f, a)
applies function f
to each member of one-dimensional array a
resulting in a new one-dimensional array over a possibly different underlying domain.
reduce(f, a, r)
applies function f
to each successive element of the one-dimensional array a
and an accumulant initialized to r
. For example, reduce(_+$Integer, [1, 2, 3], 0)
does 3+(2+(1+0))
. Note: third argument r
may be regarded as the identity element for the function f
.
scan(f, a, r)
successively applies reduce(f, x, r)
to more and more leading sub-arrays x
of one-dimensional array a
. More precisely, if a
is [a1, a2, ...]
, then scan(f, a, r)
returns [reduce(f, [a1], r), reduce(f, [a1, a2], r), ...]
.