array1.spad line 31 [edit on github]
This package provides tools for operating on primitive arrays with unary and binary functions involving different underlying types.
map(f, a)
applies function f
to each member of primitive array a
resulting in a new primitive array over a possibly different underlying domain.
reduce(f, a, r)
applies function f
to each successive element of the primitive 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 primitive array a
. More precisely, if a
is [a1, a2, ...]
, then scan(f, a, r)
returns [reduce(f, [a1], r), reduce(f, [a1, a2], r), ...]
.