The two functions partition and flatten are the primitives for moving between levels of nesting. All other functions for moving between levels of nesting can be built out of these. The functions split and bottop are often useful for divide-and-conquer routines.
partition(v, counts) {([a], [int]) [[a]] :: (a in any)}
Given a sequence of values and another sequence of counts, partition
returns a nested sequence with each subsequence being of a length
specified by the counts. The sum of the counts must equal the
length of the sequence of values.
For example:
4pt
flatten(v) {[[a]] [a] :: (a in any)}
Given a nested sequence of values, flatten flattens the sequence.
For example:
4pt
split(v, flags) {([a], [bool]) [[a]] :: (a in any)}
Given a sequence of values v and a boolean sequence of
flags, split creates a nested sequence of length
2 with all the elements with an f in
their flag in the first element and elements with a t in
their flag in the second element.
For example:
4pt
bottop(v) {[a] [[a]] :: (a in any)}
Given a sequence of values values, bottop
creates a nested sequence of length
2 with all the elements from the bottom half of the sequence in
the first element and elements from the top half of the sequence in
the second element.
For example:
4pt
head_rest(values) {[a] (a, [a]) :: (a in any)}
Given a sequence of values values of length > 0, head_rest
returns a pair containing the first element of the sequence, and the
remaining elements of the sequence.
rest_tail(values) {[a] ([a], a) :: (a in any)}
Given a sequence of values values of length > 0, rest_tail
returns a pair containing all but the last element of the sequence, and the
last element of the sequence.