OneDimensionalArrayFunctions2(A, B)ΒΆ
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: (A -> B, OneDimensionalArray A) -> OneDimensionalArray B
map(f, a)
applies functionf
to each member of one-dimensional arraya
resulting in a new one-dimensional array over a possibly different underlying domain.
- reduce: ((A, B) -> B, OneDimensionalArray A, B) -> B
reduce(f, a, r)
applies functionf
to each successive element of the one-dimensional arraya
and an accumulant initialized tor
. For example,reduce(_+\$Integer, [1, 2, 3], 0)
does3+(2+(1+0))
. Note: third argumentr
may be regarded as the identity element for the functionf
.
- scan: ((A, B) -> B, OneDimensionalArray A, B) -> OneDimensionalArray B
scan(f, a, r)
successively appliesreduce(f, x, r)
to more and more leading sub-arraysx
of one-dimensional arraya
. More precisely, ifa
is[a1, a2, ...]
, thenscan(f, a, r)
returns[reduce(f, [a1], r), reduce(f, [a1, a2], r), ...]
.