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 functionfto each member of primitive arrayaresulting in a new primitive array over a possibly different underlying domain.
- reduce: ((A, B) -> B, PrimitiveArray A, B) -> B
reduce(f, a, r)applies functionfto each successive element of the primitive arrayaand an accumulant initialized tor. For example,reduce(_+\$Integer, [1, 2, 3], 0)does3+(2+(1+0)). Note: third argumentrmay 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-arraysxof primitive arraya. More precisely, ifais[a1, a2, ...], thenscan(f, a, r)returns[reduce(f, [a1], r), reduce(f, [a1, a2], r), ...].