FiniteSetAggregateFunctions2(S, A, R, B)¶
aggcat2.spad line 122 [edit on github]
S: SetCategory
A: FiniteSetAggregate S
R: SetCategory
B: FiniteSetAggregate R
FiniteSetAggregateFunctions2 provides functions involving two finite set aggregates where the underlying domains might be different. An example of this is to create a set of rational numbers by mapping a function across a set of integers, where the function divides each integer by 1000.
- map: (S -> R, A) -> B
map(f, a)applies functionfto each member of aggregatea, creating a new aggregate with a possibly different underlying domain.
- reduce: ((S, R) -> R, A, R) -> R
reduce(f, a, r)applies functionfto each successive element of the aggregateaand an accumulant initialised tor. For example,reduce(_+\$Integer, [1, 2, 3], 0)does a3+(2+(1+0)). Note: third argumentrmay be regarded as an identity element for the function.
- scan: ((S, R) -> R, A, R) -> B
scan(f, a, r)successively appliesreduce(f, x, r)to more and more leading sub-aggregatesxof aggregatea. More precisely, ifais[a1, a2, ...], thenscan(f, a, r)returns spad {[reduce(f, [a1], r), reduce(f, [a1, a2], r), …]}.