std/seq¶
module seq for Seq<T>
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.
first— The element at position 0, ornoneover an empty sequence:[3, 1, 2] | firstis3.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".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}.