[[b2.reference.modules.sequence]]
= sequence

Various useful list functions. Note that algorithms in this module
execute largely in the caller's module namespace, so that local rules
can be used as function objects. Also note that most predicates can be
multi-element lists. In that case, all but the first element are
prepended to the first argument which is passed to the rule named by the
first element.

1. `rule filter ( predicate + : sequence * )`
+
Return the elements `e` of `$(sequence)` for which `[ $(predicate) e ]`
has a non-null value.

2. `rule transform ( function + : sequence * )`
+
Return a new sequence consisting of `[ $(function) $(e) ]` for each
element `e` of `$(sequence)`.

3. `rule reverse ( s * )`
+
Returns the elements of `s` in reverse order.

4. `rule insertion-sort ( s * : ordered * )`
+
Insertion-sort `s` using the BinaryPredicate `ordered`.

5. `rule merge ( s1 * : s2 * : ordered * )`
+
Merge two ordered sequences using the BinaryPredicate `ordered`.

6. `rule join ( s * : joint ? )`
+
Join the elements of `s` into one long string. If `joint` is supplied,
it is used as a separator.

7. `rule length ( s * )`
+
Find the length of any sequence.

8. `rule unique ( list * : stable ? )`
+
Removes duplicates from `list`. If `stable` is passed, then the order of
the elements will be unchanged.

9. `rule max-element ( elements + : ordered ? )`
+
Returns the maximum number in `elements`. Uses `ordered` for comparisons
or `numbers.less` if none is provided.

10. `rule select-highest-ranked ( elements * : ranks * )`
+
Returns all of `elements` for which the corresponding element in the
parallel list `rank` is equal to the maximum value in `rank`.
