Collection(S)

aggcat.spad line 182 [edit on github]

A collection is a homogeneous aggregate which can be built from a list of members. The operation used to build the aggregate is generically named construct. However, each collection provides its own special function with the same name as the data type, except with an initial lower case letter, e.g. list for List, flexibleArray for FlexibleArray, and so on.

# : % -> NonNegativeInteger if % has finiteAggregate
from Aggregate
= : (%, %) -> Boolean if S has SetCategory or S has BasicType and % has finiteAggregate
from BasicType
any? : (Mapping(Boolean, S), %) -> Boolean if % has finiteAggregate
from HomogeneousAggregate(S)
coerce : % -> OutputForm if S has CoercibleTo(OutputForm)
from CoercibleTo(OutputForm)
construct : List(S) -> %

construct([x, y, ..., z]) returns the collection of elements x, y, ..., z ordered as given. Equivalently written as [x, y, ..., z]$D, where D is the domain. D may be omitted for those of type List.

convert : % -> InputForm if S has ConvertibleTo(InputForm)
from ConvertibleTo(InputForm)
copy : % -> %
from Aggregate
count : (S, %) -> NonNegativeInteger if S has BasicType and % has finiteAggregate
from HomogeneousAggregate(S)
count : (Mapping(Boolean, S), %) -> NonNegativeInteger if % has finiteAggregate
from HomogeneousAggregate(S)
empty : () -> %
from Aggregate
empty? : % -> Boolean
from Aggregate
eq? : (%, %) -> Boolean
from Aggregate
eval : (%, S, S) -> % if S has Evalable(S) and S has SetCategory
from InnerEvalable(S, S)
eval : (%, Equation(S)) -> % if S has Evalable(S) and S has SetCategory
from Evalable(S)
eval : (%, List(S), List(S)) -> % if S has Evalable(S) and S has SetCategory
from InnerEvalable(S, S)
eval : (%, List(Equation(S))) -> % if S has Evalable(S) and S has SetCategory
from Evalable(S)
every? : (Mapping(Boolean, S), %) -> Boolean if % has finiteAggregate
from HomogeneousAggregate(S)
find : (Mapping(Boolean, S), %) -> Union(S, "failed")

find(p, u) returns the first x in u such that p(x) is true, and "failed" otherwise.

latex : % -> String if S has SetCategory
from SetCategory
less? : (%, NonNegativeInteger) -> Boolean
from Aggregate
map : (Mapping(S, S), %) -> %
from HomogeneousAggregate(S)
map! : (Mapping(S, S), %) -> % if % has shallowlyMutable
from HomogeneousAggregate(S)
max : % -> S if S has OrderedSet and % has finiteAggregate
from HomogeneousAggregate(S)
max : (Mapping(Boolean, S, S), %) -> S if % has finiteAggregate
from HomogeneousAggregate(S)
member? : (S, %) -> Boolean if S has BasicType and % has finiteAggregate
from HomogeneousAggregate(S)
members : % -> List(S) if % has finiteAggregate
from HomogeneousAggregate(S)
min : % -> S if S has OrderedSet and % has finiteAggregate
from HomogeneousAggregate(S)
more? : (%, NonNegativeInteger) -> Boolean
from Aggregate
parts : % -> List(S) if % has finiteAggregate
from HomogeneousAggregate(S)
reduce : (Mapping(S, S, S), %) -> S if % has finiteAggregate

reduce(f, u) reduces the binary operation f across u. For example, if u is [x, y, ..., z] then reduce(f, u) returns f(..f(f(x, y), ...), z). Note: if u has one element x, reduce(f, u) returns x. Error: if u is empty.

reduce : (Mapping(S, S, S), %, S) -> S if % has finiteAggregate

reduce(f, u, x) reduces the binary operation f across u, where x is the identity operation of f. Same as reduce(f, u) if u has 2 or more elements. Returns f(y, x) if u has one element y. Returns x if u is empty. For example, reduce(+, u, 0) returns the sum of the elements of u.

reduce : (Mapping(S, S, S), %, S, S) -> S if S has BasicType and % has finiteAggregate

reduce(f, u, x, z) reduces the binary operation f across u, stopping when an "absorbing element" z is encountered. As for reduce(f, u, x), x is the identity element of f. Same as reduce(f, u, x) when u contains no element z. Thus the third argument x is returned when u is empty.

remove : (S, %) -> % if S has BasicType and % has finiteAggregate

remove(x, u) returns a copy of u with all elements equal to x removed. Note: remove(x, u) = [y for y in u | y ~= x].

remove : (Mapping(Boolean, S), %) -> % if % has finiteAggregate

remove(p, u) returns a copy of u removing all elements x such that p(x) is true. Note: remove(p, u) = [x for x in u | not p(x)].

removeDuplicates : % -> % if S has BasicType and % has finiteAggregate

removeDuplicates(u) returns a copy of u with all duplicates removed.

sample : () -> %
from Aggregate
select : (Mapping(Boolean, S), %) -> % if % has finiteAggregate

select(p, u) returns a copy of u containing only those elements such p(x) is true. Note: select(p, u) = [x for x in u | p(x)].

size? : (%, NonNegativeInteger) -> Boolean
from Aggregate
~= : (%, %) -> Boolean if S has SetCategory or S has BasicType and % has finiteAggregate
from BasicType

BasicType

CoercibleTo(OutputForm)

HomogeneousAggregate(S)

SetCategory

Aggregate

ConvertibleTo(InputForm)

InnerEvalable(S, S)

Evalable(S)