aggcat2.spad line 122 [edit on github]
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(f, a)
applies function f
to each member of aggregate a
, creating a new aggregate with a possibly different underlying domain.
reduce(f, a, r)
applies function f
to each successive element of the aggregate a
and an accumulant initialised to r
. For example, reduce(_+$Integer, [1, 2, 3], 0)
does a 3+(2+(1+0))
. Note: third argument r
may be regarded as an identity element for the function.
scan(f, a, r)
successively applies reduce(f, x, r)
to more and more leading sub-aggregates x
of aggregate a
. More precisely, if a
is [a1, a2, ...]
, then scan(f, a, r)
returns
[reduce(f, [a1], r), reduce(f, [a1, a2], r), ...].