std/seq¶
module seq for Seq<T> : Index<T>, Slice
The sequence, set and map operations beyond the core's membership, order
and lookup, in the prelude. A receiver module over Seq<T>, with T
bound per call; a function that takes any collection writes its receiver,
self: Collection<T>, and the functions over sets and maps take theirs as
a typed first parameter. A receiver S : Seq<T> comes back at its own
type, and F<_> : Seq<_> rebuilt in its own constructor. Every sequence
implements Index<T> and Slice through at and slice: xs[i] is
xs.at(i), and xs[a:b] is xs.slice(Range(start = a, end = b)).
at— The element ofselfatposition, ornonepast either end; a negative position counts from the end:[3, 1, 2].at(1)and[3, 1, 2][1]are1.slice— The elements ofselfwithinrange, clamped to the sequence, a negative bound counting from the end:[1, 2, 3][1:]is[2, 3].first— The element at position 0, ornoneover an empty sequence:[3, 1, 2] | firstis3.one— The one element ofself: a sequence of exactly one.last— The element at the last position, ornoneover an empty sequence:[3, 1, 2] | lastis2.reverse— The elements ofselfin the opposite order, in its own constructor:[1, 2, 3] | reverseis[3, 2, 1].distinct— Each value ofselfonce, at its first position, at the type ofself:[1, 2, 1, 3, 2] | distinctis[1, 2, 3].zip— Pairs of the elements ofselfandotherat equal positions, as long as the shorter:[1, 2, 3] | zip(["a", "b"])is[Pair(first = 1, second = "a"), Pair(first = 2, second = "b")].enumerate— Each element ofselfpaired with its position, counting from 0:["a", "b"] | enumerateis[Pair(first = 0, second = "a"), Pair(first = 1, second = "b")].any— Whetherbyholds of some value ofself;falseover an empty collection:[1, 2, 3] | any(x => x > 2)istrue.all— Whetherbyholds of every value ofself;trueover an empty collection:[] | all(x => x > 2)istrue.find— The first element ofselfthatbyaccepts, ornone:[1, 2, 3, 4] | find(x => x > 2)is3.position— The position of the first element ofselfthatbyaccepts, counting from 0, ornone:[1, 2, 3, 4] | position(x => x > 2)is2.take_while— The leading values ofselfthatbyaccepts, up to the first it rejects:[1, 2, 5, 1] | take_while(x => x < 3)is[1, 2].drop_while— The values ofselfafter the leading onesbyaccepts, at the type ofself:[1, 2, 5, 1] | drop_while(x => x < 3)is[5, 1].window— Every run ofnconsecutive elements ofself, in order:[1, 2, 3, 4] | window(2)is[[1, 2], [2, 3], [3, 4]].partition— The values ofselfredistributed by the keybygives: each value once, at its own type, those of one key in one logical partition.is_empty— Whetherselfhas no values:[] | is_emptyistrue.join— Every pair of a value ofselfand a value ofotherthatbyrelates, in the order ofself, then ofother:[1, 2] | join([1, 2, 3], (a, b) => a < b)gives the pairs(1, 2),(1, 3)and(2, 3).min_by— The value ofselfthat is least, by the keybygives or by theOrderingbygives two values; the first of equals, ornoneover an empty collection:["bb", "a", "ccc"] | min_by(s => size(s))is"a".max_by— The value ofselfthat is greatest, by the keybygives or by theOrderingbygives two values; the first of equals, ornoneover an empty collection:["bb", "a", "ccc"] | max_by(s => size(s))is"ccc".over— Each value ofself, at its input position, as whatintogives for it and itsWindow: the values with its keyby, ordered byorder, a key or a comparison.row_number— The row's position in its ordered partition, from 1; no two rows share one.rank— One more than the number of rows strictly before the row: rows equal under the order share it, and the next skips the shared positions.dense_rank— The row's rank counting each set of equal rows once: rows equal under the order share it, and the next is one more.lag— The rownpositions before, ornonebefore the first.lead— The rownpositions after, ornonepast the last.running— The rows from the first up to and including the row, in order: SQL'sROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW.rows— The rows frombeforepositions before the row toafterpositions after it, clipped to the partition.whole— Every row of the partition, in order.to_map— A map from thekeyof each value ofselfto itsvalue; two values with one key are an evaluation error:["bb", "a"] | to_map(s => s, s => size(s))isMap {"bb": 2, "a": 1}.range— TheInts fromstartup to, not including,end, eachstepafter the one before:range(1, 6)is[1, 2, 3, 4, 5], andrange(10, 0, -3)is[10, 7, 4, 1].with— The mapselfwithkeyset tovalue, added or replaced, at the type ofself:Map(["a"], [1]) | with("b", 2)isMap {"a": 1, "b": 2}.without— The mapselfwithoutkey, whether or not it held it, at the type ofself:Map(["a", "b"], [1, 2]) | without("a")isMap {"b": 2}.entries— Each association of the mapselfas aPairof its key and its value, in the map's order.values— The values of the mapself, in the map's order:Map(["b", "a"], [2, 1]) | valuesis[2, 1].intersection— The members of bothselfandother, at the type ofself:{1, 2, 3} | intersection({2, 3, 4})is{2, 3}.difference— The members ofselfthatotherdoes not hold, at the type ofself:{1, 2, 3} | difference({2, 3, 4})is{1}.