PrimitiveArrayFunctions2(A, B)ΒΆ
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: (A -> B, PrimitiveArray A) -> PrimitiveArray B
map(f, a)
applies functionf
to each member of primitive arraya
resulting in a new primitive array over a possibly different underlying domain.
- reduce: ((A, B) -> B, PrimitiveArray A, B) -> B
reduce(f, a, r)
applies functionf
to each successive element of the primitive 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, PrimitiveArray A, B) -> PrimitiveArray B
scan(f, a, r)
successively appliesreduce(f, x, r)
to more and more leading sub-arraysx
of primitive arraya
. More precisely, ifa
is[a1, a2, ...]
, thenscan(f, a, r)
returns[reduce(f, [a1], r), reduce(f, [a1, a2], r), ...]
.