std/collections¶
module collections
The operations over the collection types core declares: membership,
filtering, mapping, order, grouping, joins and reductions. Each one is
callable directly or as a pipeline step, and carries the shape a planner
splits it by.
Group— One partition of agroup: itskey, and the occurrences with that key in input order, asitems.size— The number of element occurrences inself, anInt:[1, 2, 2, 3] | sizeis4, andSet([1, 2, 2]) | sizeis2.count— The number of element occurrences inself, assizegives it:countis the kept alias ofsize.contains—truewhenvalueoccurs inself, andfalseotherwise:[1, 2, 3] | contains(2)istrue.get— The value a map holds forkey, ornonewhen the key is missing:{"a": 1} | get("a")is1, and{"a": 1} | get("b")isnone.filter— The elements for which a type test holds, each at the tested type.of_type— The elements whose runtime type istypeor one of its subtypes, each at that type, in anF<U>:filter(x => x | is(U)).is—truewhen the runtime type ofselfistypeor one of its subtypes.somes— The present values of a collection of options, in anF<T>; the absent ones are dropped:[some(1), none, some(3)] | somesis[1, 3].oks— The success values of a collection of results, in anF<T>; the failures are dropped:[ok(1), err("x"), ok(3)] | oksis[1, 3].errs— The error values of a collection of results, in anF<E>; the successes are dropped:[ok(1), err("x"), ok(3)] | errsis["x"].map— Each element throughby, in a collection of the input's constructor:[1, 2, 3] | map(x => x * 10)is[10, 20, 30].retry— Each element through the fallibleoperation, invoked again while it fails with an errorwhenaccepts (every error, withoutwhen) and fewer thanattemptsinvocations have run.take— The firstnelements.drop— The elements after the firstn, in the input's order and type:[5, 3, 4] | drop(1)is[3, 4].collect— Consecutive elements in batches ofn, in order; the last batch may be shorter:[1, 2, 3, 4, 5] | collect(2)is[[1, 2], [3, 4], [5]].emit— Every member of every sequence, in order, the inverse ofcollect:[[1, 2], [3]] | emitis[1, 2, 3].flat_map— Each element throughbyto a sequence, and the members of those sequences in order:map(by) | emit.sort— The elements in ascending order: by their own value order, by the keybygives each, or by a comparisonbyof two elements.group— The occurrences partitioned by the keybygives each, as a set ofGroups, each a key and its occurrences in input order.join— The pairs of an element of the input and an element ofotherthat match, each built byinto, ordered by the input element's position, thenother's.left_join— Ajointhat keeps every element of the input: one with no match inotheris built byintowithnoneon the right.right_join— Ajointhat keeps every element ofother: one with no match in the input is built byintowithnoneon the left.full_join— Ajointhat keeps every element of both sides, withnonefor the missing side; the unmatched elements ofothercome after the matched results.cross_join— Every pair of an element of the input and an element ofother, built byinto, in order, with no condition:[1, 2] | cross_join(["a", "b"], into = (x, y) => [x, y])is[[1, "a"], [1, "b"], [2, "a"], [2, "b"]].semi_join— The elements of the input that match some element ofother, by keys, a predicateon, or both; each is kept at most once, in its position.anti_join— The elements of the input that match no element ofother, by keys, a predicateon, or both, in their positions.reduce— The elements folded from the left byby, frominitial, or without it from the first element, the result thennoneover[]:[1, 2, 3] | reduce(0, (a, x) => a + x)is6.sum— The sum of the occurrences,reduce(0, +);[] | sumis0.product— The product of the occurrences,reduce(1, *);[] | productis1.average— The mean of the occurrences, ornoneover[]:[1, 2] | averageis1.5.merge_all— Every map merged in order, a later key winning:reduce({:}, merge).union_all— Every member of every set:reduce(Set([]), union).concat_all— Every member of every sequence, in order:reduce([], concat).min— The least occurrence by value order,reduce(min), ornoneover[].max— The greatest occurrence by value order,reduce(max), ornoneover[].variance— The population variance of the occurrences, as aFloat, ornoneover[]:[1, 2, 3, 4] | varianceis1.25.count_by— The number of occurrences with each keybygives, as a map from key to count; empty over[].histogram— The number of occurrences in each bucket ofwidth, keyed by the bucket's lower bound, the greatest multiple ofwidthnot above the value, in key order:[1, 5, 12, -3] | histogram(5)isSortedMap {-5: 1, 0: 1, 5: 1, 10: 1}.top_k— Thekgreatest occurrences, by value order or by the keybygives, greatest first, equal keys in input order:[3, 1, 4, 1, 5] | top_k(2)is[5, 4].approx_distinct— An estimate of the number of distinct occurrences,size(Set(xs));0over[].