sequence¶
fun iter_key(Iterator: any): anyTBD
fun iter_next(Iterator: any): iteratorTBD
fun iter_value(Iterator: any): anyTBD
fun iterate(Sequence: any): iteratorTBD
meth @(Value: any): sequenceReturns an infinite sequence that repeatedly produces
Value. Should be used with:limitor paired with a finite sequence inzip,weave, etc.list(@1 limit 10) :> [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
meth (Initial: any) @ (Fn: function): sequenceReturns a sequence that produces
Initial,Fn(Initial),Fn(Fn(Initial)), ... stopping whenFn(Last)returnsnil.list(1 @ (_ + 1) limit 10) :> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
type chained < function, sequenceA chained function or sequence, consisting of a base function or sequence and any number of additional functions or filters.
When used as a function or sequence, the base is used to produce an initial result, then the additional functions are applied in turn to the result.
Filters do not affect the result but will shortcut a function call or skip an iteration if
nilis returned. I.e. filters remove values from a sequence that fail a condition without affecting the values that pass.fun chained(Base: any, Fn₁, : function, ...): chainedReturns a new chained function or sequence with base
Baseand additional functions or filtersFn₁, ..., Fnₙ.let F := chained(fun(X) X + 1, fun(X) X ^ 2) F(10) :> 121
meth ^(Function: function): sequenceReturns a sequence that generates the result of calling
Function()at each iteration untilnilis returned.let L := [1, 2, 3, 4] list(^fun L:pull) :> [4, 3, 2, 1]
meth (Function: function):repeat: sequenceReturns a sequence that generates the result of calling
Function()at each iteration untilnilis returned.Deprecated since version 2.9.0: Use
^instead.let L := [1, 2, 3, 4] list(L:pull(_):repeat) :> [4, 3, 2, 1]
fun top(N: integer, Sequence: sequence, Fn: function): sequenceReturns the top
Nvalues ofSequencebased onFn(Valueᵢ).fun top2(N: integer, Sequence: sequence, Fn: function): sequenceReturns the top
Nvalues and priorities ofSequencebased onFn(Valueᵢ).meth (Buffer: string::buffer):append(Value: real::range)Appends a representation of
ValuetoBuffer.type sequenceThe base type for any sequence value.
fun all(Sequence: sequence): some | nilReturns
nilifnilis produced bySequence. Otherwise returnssome. IfSequenceis empty, thensomeis returned.all([1, 2, 3, 4]) :> some all([1, 2, nil, 4]) :> nil all([]) :> some
fun batch(Sequence: sequence, Size: integer, Shift?: integer, Function: function): sequenceReturns a new sequence that calls
Functionwith each batch ofSizevalues produced bySequenceand produces the results. If aShiftis provided thenSize - Shiftvalues of each batch come from the previous batch.list(batch(1 .. 20, 4, tuple)) :> [(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12), (13, 14, 15, 16), (17, 18, 19, 20)] list(batch(1 .. 20, 4, 2, tuple)) :> [(1, 2, 3, 4), (3, 4, 5, 6), (5, 6, 7, 8), (7, 8, 9, 10), (9, 10, 11, 12), (11, 12, 13, 14), (13, 14, 15, 16), (15, 16, 17, 18), (17, 18, 19, 20)]
fun count(Sequence: sequence): integerReturns the count of the values produced by
Sequence. For some types of sequences (e.g.list,map, etc), the count is simply retrieved. For all other types, the sequence is iterated and the total number of values counted.count([1, 2, 3, 4]) :> 4 count(1 .. 10 ->? (2 | _)) :> 5
fun count2(Sequence: sequence): mapReturns a map of the values produced by
Sequencewith associated counts.count2("banana") :> {"b" is 1, "a" is 3, "n" is 2}
fun distill(Initial?: any, Sequence: sequence, Fn: function): any | nilReturns a sequence that produces
Fn(Initial, V₁),Fn(Fn(Initial, V₁), V₂), ... ifInitialis provided, otherwise returns a sequence that producesV₁,Fn(V₁, V₂),Fn(Fn(V₁, V₂), V₃), ... .The resulting sequence always has the same number of values as
Sequence.list(distill(1 .. 10, +)) :> [1, 3, 6, 10, 15, 21, 28, 36, 45, 55] list(distill(20, 1 .. 10, +)) :> [21, 23, 26, 30, 35, 41, 48, 56, 65, 75]
fun dup(Sequence: sequence)Returns a new sequence which produces the values of
Sequenceas both keys and values.map(dup({"A" is 1, "B" is 2, "C" is 3})) :> {1 is 1, 2 is 2, 3 is 3}
fun fold(Sequence: sequence): sequenceReturns a new sequence that treats alternating values produced by
Sequenceas keys and values respectively.map(fold(1 .. 10)) :> {1 is 2, 3 is 4, 5 is 6, 7 is 8, 9 is 10}
fun grid(Sequence₁, : sequence, ..., Function: any): sequenceReturns a new sequence that produces
Function(V₁, V₂, ..., Vₙ)for all possible combinations ofV₁, ..., Vₙ, whereVᵢare the values produced bySequenceᵢ.list(grid(1 .. 3, "cake", [true, false], tuple)) :> [(1, c, true), (1, c, false), (1, a, true), (1, a, false), (1, k, true), (1, k, false), (1, e, true), (1, e, false), (2, c, true), (2, c, false), (2, a, true), (2, a, false), (2, k, true), (2, k, false), (2, e, true), (2, e, false), (3, c, true), (3, c, false), (3, a, true), (3, a, false), (3, k, true), (3, k, false), (3, e, true), (3, e, false)] list(grid(1 .. 3, "cake", *)) :> ["c", "a", "k", "e", "cc", "aa", "kk", "ee", "ccc", "aaa", "kkk", "eee"]
fun key(Sequence: sequence)Returns a new sequence which produces the keys of
Sequence.list(key({"A" is 1, "B" is 2, "C" is 3})) :> ["A", "B", "C"]
fun max(Sequence: sequence): any | nilReturns the largest value (using
:max) produced bySequence.max([1, 5, 2, 10, 6]) :> 10
fun max2(Sequence: sequence): tuple | nilReturns a tuple with the key and value of the largest value (using
>) produced bySequence. ReturnsnilifSequenceis empty.max2([1, 5, 2, 10, 6]) :> (4, 10)
fun min(Sequence: sequence): any | nilReturns the smallest value (using
:min) produced bySequence.min([1, 5, 2, 10, 6]) :> 1
fun min2(Sequence: sequence): tuple | nilReturns a tuple with the key and value of the smallest value (using
<) produced bySequence. ReturnsnilifSequenceis empty.min2([1, 5, 2, 10, 6]) :> (1, 1)
fun pair(Sequence₁: sequence, Sequence₂: sequence): sequenceReturns a new sequence that produces the values from
Sequence₁as keys and the values fromSequence₂as values.fun prod(Sequence: sequence): any | nilReturns the product of the values (using
*) produced bySequence.prod([1, 5, 2, 10, 6]) :> 600
fun range(Sequence: sequence): tuple[any, any] | nilReturns the smallest and largest values (using
:minand:max) produced bySequence.range([1, 5, 2, 10, 6]) :> (1, 10)
fun reduce(Initial?: any, Sequence: sequence, Fn: function): any | nilReturns
Fn(Fn( ... Fn(Initial, V₁), V₂) ..., Vₙ)whereVᵢare the values produced bySequence. IfInitialis omitted, the first value produced bySequenceis used.reduce(1 .. 10, +) :> 55 reduce([], 1 .. 10, :put) :> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
fun reduce2(Initial?: any, Sequence: sequence, Fn: function): any | nilReturns
Fn(Fn( ... Fn(Initial, K₁, V₁), K₂, V₂) ..., Kₙ, Vₙ)whereKᵢandVᵢare the keys and values produced bySequence. IfInitialis omitted, a tuple with the first key and value produced bySequenceis used.reduce2([], "cake", fun(L, K, V) L:put((K, V))) :> [(1, c), (2, a), (3, k), (4, e)]
fun some(Sequence: sequence): any | nilReturns the first value produced by
Sequencethat is notnil.some([nil, nil, "X", nil]) :> "X" some([nil, nil, nil, nil]) :> nil
fun sum(Sequence: sequence): any | nilReturns the sum of the values (using
+) produced bySequence.sum([1, 5, 2, 10, 6]) :> 24
fun swap(Sequence: sequence)Returns a new sequence which swaps the keys and values produced by
Sequence.map(swap("cake")) :> {"c" is 1, "a" is 2, "k" is 3, "e" is 4}
fun unfold(Sequence: sequence): sequenceReturns a new sequence that treats produces alternatively the keys and values produced by
Sequence.list(unfold("cake")) :> [1, "c", 2, "a", 3, "k", 4, "e"]
fun unique(Sequence: sequence): sequenceReturns an sequence that returns the unique values produced by
Sequence. Uniqueness is determined by using amap.list(unique("banana")) :> ["b", "a", "n"]
fun unique1(Sequence: sequence): sequenceReturns an sequence that returns the unique keys produced by
Sequence. Uniqueness is determined by using amap.list(unique1("banana")) :> ["b", "a", "n", "a", "n", "a"]
fun unpack(Sequence: sequence): sequenceReturns a new sequence unpacks each value generated by
Sequenceas keys and values respectively.let L := [("A", "a"), ("B", "b"), ("C", "c")] map(unpack(L)) :> {"A" is "a", "B" is "b", "C" is "c"}
fun weave(Sequence₁, : sequence, ...): sequenceReturns a new sequence that produces interleaved values
Vᵢfrom each ofSequenceᵢ. The sequence stops produces values when any of theSequenceᵢstops.list(weave(1 .. 3, "cake")) :> [1, "c", 2, "a", 3, "k"]
fun zip(Sequence₁, : sequence, ..., Function: any): sequenceReturns a new sequence that produces
Function(V₁₁, ..., Vₙ₁), Function(V₁₂, ..., Vₙ₂), ...whereVᵢⱼis thej-th value produced bySequenceᵢ. The sequence stops produces values when any of theSequenceᵢstops.list(zip(1 .. 3, "cake", tuple)) :> [(1, c), (2, a), (3, k)]
fun zip2(Sequence₁, : sequence, ..., KeyFn: any, ValueFn: any): sequenceReturns a new sequence that produces
KeyFn(K₁₁, ..., Kₙ₁) - ValueFn(V₁₁, ..., Vₙ₁), ...whereKᵢⱼ - Vᵢⱼare thej-th key and value produced bySequenceᵢ. The sequence stops produces values when any of theSequenceᵢstops.map(zip2(1 .. 3, "cake", tuple, tuple)) :> {(1, 1) is (1, c), (2, 2) is (2, a), (3, 3) is (3, k)}
meth &(Sequence: sequence): SequenceReturns an sequence that repeatedly produces the values from
Sequence(for use withlimit).list(&(1 .. 3) limit 10) :> [1, 2, 3, 1, 2, 3, 1, 2, 3, 1]
meth (Sequence₁: sequence) & (Sequence₂: sequence): SequenceReturns an sequence that produces the values from
Sequence₁followed by those fromSequence₂.list(1 .. 3 & "cake") :> [1, 2, 3, "c", "a", "k", "e"]
meth (Base: sequence) -> (F: function): sequenceReturns a chained sequence equivalent to
(K₁, F(V₁)), ..., (Kₙ, F(Vₙ))whereKᵢandVᵢare the keys and values produced byBase.meth (Base: sequence) ->! (F: function): sequenceReturns a chained sequence equivalent to
(K₁, F ! V₁), ..., (Kₙ, F ! Vₙ)whereKᵢandVᵢare the keys and values produced byBase.map({"A" is [1, 2], "B" is [3, 4], "C" is [5, 6]} ->! +) :> {"A" is 3, "B" is 7, "C" is 11}
meth (Base: sequence) ->!? (F: function): sequenceReturns a chained sequence equivalent to
(Kⱼ, Vⱼ), ...whereKᵢandVᵢare the keys and values produced byBaseandF ! Vⱼreturns non-nil.map({"A" is [1, 2], "B" is [3, 3], "C" is [5, 6]} ->!? !=) :> {"A" is [1, 2], "C" is [5, 6]}
meth (Sequence: sequence) ->> (Function: function): sequenceReturns a new sequence that generates the keys and values from
Function(Value)for each value generated bySequence.list(1 .. 5 ->> (1 .. _)) :> [1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5]
meth (Base: sequence) ->? (F: function): sequenceReturns a chained sequence equivalent to
(Kⱼ, Vⱼ), ...whereKᵢandVᵢare the keys and values produced byBaseandF(Vⱼ)returns non-nil.list(1 .. 10 ->? (2 | _)) :> [2, 4, 6, 8, 10]
meth (Base: sequence) ->| (F: function): sequenceReturns a chained sequence equivalent to
(Kⱼ, Vⱼ), ...whereKᵢandVᵢare the keys and values produced byBasewhileF(Vⱼ)returns non-nil.list(1 .. 10 ->? (5 !| _)) :> [1, 2, 3, 4, 6, 7, 8, 9] list(1 .. 10 ->| (5 !| _)) :> [1, 2, 3, 4]
meth (Sequence: sequence) // (Initial: any, Fn: function): sequenceReturns a sequence that produces
Initial,Fn(Initial, V₁),Fn(Fn(Initial, V₁), V₂), ... .Deprecated since version 2.9.0: Use
distillinstead.list(1 .. 10 // (10, +)) :> [11, 13, 16, 20, 25, 31, 38, 46, 55, 65]
meth (Sequence: sequence) // (Fn: function): sequenceReturns a sequence that produces
V₁,Fn(V₁, V₂),Fn(Fn(V₁, V₂), V₃), ... .Deprecated since version 2.9.0: Use
distillinstead.list(1 .. 10 // +) :> [1, 3, 6, 10, 15, 21, 28, 36, 45, 55]
meth (Base: sequence) => (F: function): sequenceReturns a chained sequence equivalent to
(K₁, F(K₁, V₁)), ..., (Kₙ, F(Kₙ, Vₙ))whereKᵢandVᵢare the keys and values produced byBase.map("cake" => *) :> {1 is "c", 2 is "aa", 3 is "kkk", 4 is "eeee"}
meth (Base: sequence) => (F₁: function, F₂: function): sequenceReturns a chained sequence equivalent to
(F₁(K₁, V₁), F₂(K₁, V₁)), ..., (F₁(Kₙ, Vₙ), F₂(Kₙ, Vₙ))whereKᵢandVᵢare the keys and values produced byBase.map("cake" => (tuple, *)) :> {(1, c) is "c", (2, a) is "aa", (3, k) is "kkk", (4, e) is "eeee"}
meth (Sequence: sequence) =>> (Function: function): sequenceReturns a new sequence that generates the keys and values from
Function(Key, Value)for each key and value generated bySequence.list("cake" =>> *) :> ["c", "a", "a", "k", "k", "k", "e", "e", "e", "e"]
meth (Base: sequence) =>? (F: function): sequenceReturns a chained sequence equivalent to
(Kⱼ, Vⱼ), ...whereKᵢandVᵢare the keys and values produced byBaseandF(Kⱼ, Vⱼ)returns non-nil.let M := map(1 .. 10 -> fun(X) X ^ 2 % 10) :> {1 is 1, 2 is 4, 3 is 9, 4 is 6, 5 is 5, 6 is 6, 7 is 9, 8 is 4, 9 is 1, 10 is 0} map(M =>? !=) :> {2 is 4, 3 is 9, 4 is 6, 7 is 9, 8 is 4, 9 is 1, 10 is 0}
meth (Base: sequence) =>| (F: function): sequenceReturns a chained sequence equivalent to
(Kⱼ, Vⱼ), ...whereKᵢandVᵢare the keys and values produced byBasewhileF(Kⱼ, Vⱼ)returns non-nil.let M := map(1 .. 10 -> fun(X) X ^ 2 % 10) :> {1 is 1, 2 is 4, 3 is 9, 4 is 6, 5 is 5, 6 is 6, 7 is 9, 8 is 4, 9 is 1, 10 is 0} map(M =>? fun(K, V) K + V < 15) :> {1 is 1, 2 is 4, 3 is 9, 4 is 6, 5 is 5, 6 is 6, 8 is 4, 9 is 1, 10 is 0} map(M =>| fun(K, V) K + V < 15) :> {1 is 1, 2 is 4, 3 is 9, 4 is 6, 5 is 5, 6 is 6}
meth (Sequence: sequence) ^ (Function: function): sequenceReturns a new sequence that generates the keys and values from
Function(Value)for each value generated bySequence.Deprecated since version 2.5.0: Use
->>instead.list(1 .. 5 ^ (1 .. _)) :> [1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5]
meth (Sequence: sequence):after(Value: any): sequenceReturns an sequence that skips initial values not equal to
Valueand skipsValueitself once.list("banana") :> ["b", "a", "n", "a", "n", "a"] list("banana" after "n") :> ["a", "n", "a"]
meth (Sequence: sequence):apply(Fn: function): sequenceCalls
Fn(Key, Value)for each key and value produced bySequence, then returnsSequence.meth (Arg₁: sequence):before(Arg₂: any)TBD
meth (Sequence: sequence):chunk(Size: integer): sequenceReturns a sequence of sequences, each of which produces the next
Sizekey-value pairs fromSequence.list("aAaAaabBbbbBaAAAaacccCCCccbcB" chunk 5, list) :> [["a", "A", "a", "A", "a"], ["a", "b", "B", "b", "b"], ["b", "B", "a", "A", "A"], ["A", "a", "a", "c", "c"], ["c", "C", "C", "C", "c"], ["c", "b", "c", "B"]]
meth (Sequence: sequence):find(Value: any): any | nilReturns the first key generated by
Sequencewith corresponding value= Value.map("a" .. "z"):find("j") :> 106
meth (Sequence: sequence):find(Value: any, Fn: function): any | nilReturns the first key generated by
Sequencewith corresponding value satisfyingFn(_, Value).map("a" .. "z"):find("j", <) :> 107
meth (Sequence: sequence):first(...): any | nilReturns the first value produced by
Sequence.first("cake") :> "c" first([]) :> nil
meth (Sequence: sequence):first2(...): tuple(any, any) | nilReturns the first key and value produced by
Sequence.first2("cake") :> (1, c) first2([]) :> nil
meth (Sequence: sequence):from(Value: any): sequenceReturns an sequence that skips initial values not equal to
Value.list("banana") :> ["b", "a", "n", "a", "n", "a"] list("banana" from "n") :> ["n", "a", "n", "a"]
meth (Sequence: sequence):generate(Function: function): functionReturns a new function that returns
Function(Key, Value)whereKeyandValueare the next key-value pair generated bySequence. OnceSequenceis exhausted, the function returnsnil.let f := "cat" generate tuple :> <generator> f() :> (1, c) f() :> (2, a) f() :> (3, t) f() :> nil f() :> nil
meth (Sequence: sequence):group(Fn: function): sequenceReturns a sequence of sequences, each of which produces the key-value pairs from
Sequenceup to the value ofFn(Value)changing.list("aAaAaabBbbbBaAAAaacccCCCccbcB" group :upper, list) :> [["a", "A", "a", "A", "a", "a"], ["b", "B", "b", "b", "b", "B"], ["a", "A", "A", "A", "a", "a"], ["c", "c", "c", "C", "C", "C", "c", "c"], ["b"], ["c"], ["B"]]
meth (Sequence: sequence):join: stringJoins the elements of
Sequenceinto a string.1 .. 10 join "," :> "1,2,3,4,5,6,7,8,9,10"
meth (Sequence: sequence):join(Separator: string): stringJoins the elements of
Sequenceinto a string usingSeparatorbetween elements.(1 .. 10):join :> "12345678910"
meth (Sequence: sequence):last(...): any | nilReturns the last value produced by
Sequence.last("cake") :> "e" last([]) :> nil
meth (Sequence: sequence):last2(...): tuple(any, any) | nilReturns the last key and value produced by
Sequence.last2("cake") :> (4, e) last2([]) :> nil
meth (Sequence: sequence):limit(Limit: integer): sequenceReturns an sequence that produces at most
Limitvalues fromSequence.list(1 .. 10) :> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] list(1 .. 10 limit 5) :> [1, 2, 3, 4, 5]
meth (Sequence: sequence):limit(Limit: nil): SequenceReturns
Sequence, useful for cases whereLimitis an optional argument.meth (Sequence: sequence):provided(Fn: function): sequenceReturns an sequence that stops when
Fn(Value)isnil.list("banana") :> ["b", "a", "n", "a", "n", "a"] list("banana" provided (_ != "n")) :> ["b", "a"]
meth (Sequence: sequence):random(...): any | nilReturns a random value produced by
Sequence.random("cake") :> "c" random([]) :> nil
meth random::by(Sequence: sequence, ...)Returns a random key produced by
Sequenceweighted by its values.count2(1 .. 60000;) random::by(swap("cat")) :> {"a" is 20043, "t" is 29947, "c" is 10010}
meth (Sequence: sequence):skip(Skip: integer): sequenceReturns an sequence that skips the first
Skipvalues fromSequenceand then produces the rest.list(1 .. 10) :> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] list(1 .. 10 skip 5) :> [6, 7, 8, 9, 10]
meth (Sequence: sequence):skip(Skip: nil): SequenceReturns
Sequence, useful for cases whereSkipis an optional argument.meth (Sequence: sequence):skipuntil(Fn: function): sequenceReturns an sequence that skips initial values for which which
Fn(Value)isnil.list("banana") :> ["b", "a", "n", "a", "n", "a"] list("banana" skipuntil (_ != "b")) :> ["a", "n", "a", "n", "a"]
meth (Sequence: sequence):split(Fn: function): sequenceReturns a sequence of sequences, each of which produces the key-value pairs from
Sequence, stopping whenFn(Value)returnsnil. Empty sub-sequences are not produced.list("a" .. "z" split fun(C) not "aeiou" find C, list) :> [["b", "c", "d"], ["f", "g", "h"], ["j", "k", "l", "m", "n"], ["p", "q", "r", "s", "t"], ["v", "w", "x", "y", "z"]]
meth (Buffer: string::buffer):append(Sequence: sequence, Separator: string): some | nilAppends the values generated by
SequencetoBufferseparated bySeparator.meth (Arg₁: type):random(...)TBD