aggcat.spad line 1698 [edit on github]
A linear aggregate is an aggregate whose elements are indexed by integers. Examples of linear aggregates are strings, lists, and arrays. Most of the exported operations for linear aggregates are non-destructive but are not always efficient for a particular aggregate. For example, concat of two lists needs only to copy its first argument, whereas concat of two arrays needs to copy both arguments. Most of the operations exported here apply to infinite objects (e.g. streams) as well to finite ones. If the aggregate is a finite aggregate then it has several additional exports such as reverse, sort, and so on.
concat(u, v)
returns an aggregate consisting of the elements of u
followed by the elements of v
. Note: if w = concat(u, v)
then w.i = u.i for i in indices u
and w.(j + maxIndex u) = v.j for j in indices v
.
concat(u, x)
returns aggregate u
with additional element x
at the end. Note: for lists, concat(u, x) = concat(u, [x])
.
concat(x, u)
returns aggregate u
with additional element x
at the front. Note: for lists: concat(x, u) = concat([x], u)
.
concat(u)
, where u
is a list of aggregates [a, b, ..., c]
, returns a single aggregate consisting of the elements of a
followed by those of b
followed ... by the elements of c
. Note: concat([a, b, ..., c]) = concat(a, concat([b, ..., c]))
.
copyInto!(u, v, i)
returns aggregate u
containing a copy of v
inserted at element i
.
delete(u, i)
returns a copy of u
with the i
th element deleted. Note: delete(u, i) = concat(u(minIndex(u)..i - 1), u(i + 1..))
.
delete(u, i..j)
returns a copy of u
with the i
th through j
th element deleted. Note: delete(u, i..j) = concat(u(minIndex(u)..i-1), u(j+1..))
.
first(u, n)
returns a copy of the first n
elements of u
. Error: if u
has less than n
elements.
insert(v, u, i)
returns a copy of u
having v
inserted beginning at the i
th element. Note: insert(v, u, i) = concat(u(minIndex(u)..i-1), concat(v, u(i..)))
.
insert(x, u, i)
returns a copy of u
having x
as its i
th element. Note: insert(x, u, i) = concat(u(minIndex(u)..i-1), concat(x, u(i..)))
.
leftTrim(u, x)
returns a copy of u
with all leading x
deleted. For example, leftTrim(" abc ", char " ")
returns "abc "
.
map(f, u, v)
returns a new aggregate w
with elements z = f(x, y)
for corresponding elements x
and y
from u
and v
. Note: w.i = f(u.i, v.i)
.
merge(u, v)
merges u
and v
in ascending order. Note: merge(u, v) = merge(<=, u, v)
.
merge(p, a, b)
returns an aggregate c
which merges a
and b
. The result is produced by examining each element x
of a
and y
of b
successively. If p(x, y)
is true
, then x
is inserted into the result; otherwise y
is inserted. If x
is chosen, the next element of a
is examined, and so on. When all the elements of one aggregate are examined, the remaining elements of the other are appended. For example, merge(<, [1, 3], [2, 7, 5])
returns [1, 2, 3, 7, 5]
.
new(n, x)
returns a new aggregate of size n
all of whose entries are x
.
position(x, a)
returns the index i
of the first occurrence of x
in a, and minIndex(a) - 1
if there is no such x
.
position(x, a, n)
returns the index i
of the first occurrence of x
in a
where i >= n
, and minIndex(a) - 1
if no such x
is found.
position(p, a)
returns the index i
of the first x
in a
such that p(x)
is true
, and minIndex(a) - 1
if there is no such x
.
reverse(a)
returns a copy of a
with elements in reverse order.
reverse!(u)
returns u
with its elements in reverse order.
rightTrim(u, x)
returns a copy of u
with all trailing occurrences of x
deleted. For example, rightTrim(" abc ", char " ")
returns " abc"
.
setelt!(u, i..j, x)
(also written: u(i..j) := x
) destructively replaces each element in the segment u(i..j)
by x
. The value x
is returned. Note: u
is destructively changed so that u.k := x for k in i..j
; its length remains unchanged.
sort(u)
returns an u
with elements in ascending order. Note: sort(u) = sort(<, u)
.
sort(p, a)
returns a copy of a
sorted using total ordering predicate p
.
sort!(u)
returns u
with its elements in ascending order.
sort!(p, u)
returns u
with its elements ordered by p
.
sorted?(u)
tests if the elements of u
are in ascending order.
sorted?(p, a)
tests if a
is sorted according to predicate p
.
trim(u, x)
returns a copy of u
with all occurrences of x
deleted from right and left ends. For example, trim(" abc ", char " ")
returns "abc"
.
InnerEvalable(S, S)
Evalable(S)
Collection(S)