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 functionf
to 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 functionf
to each successive element of the aggregatea
and an accumulant initialised tor
. For example,reduce(_+\$Integer, [1, 2, 3], 0)
does a3+(2+(1+0))
. Note: third argumentr
may 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-aggregatesx
of aggregatea
. More precisely, ifa
is[a1, a2, ...]
, thenscan(f, a, r)
returns spad {[reduce(f, [a1], r), reduce(f, [a1, a2], r), …]}.