keen/col/util

Source
This is a standard module and does not need to be explicitly imported.
array-like[col, elem] spec col size
subscript elem(a col, index nat32)
buffer-like[col, elem] spec (col, elem) array-like
set-subscript void(a col, index nat32, value elem)
for-loop[col, elem] void(a col, f void mut(elem)) (col, elem) some
Calls f for each element in the collection and returns nothing.
for-loop[out-col, out-elem, in-col, in-elem] out-col(a in-col, f out-elem mut(in-elem)) (out-col, out-elem) list-new, (in-col, in-elem) some, in-col size
Calls f for each element in the input collection and returns an output collection of the results of f.
fold[t, col, elem] t(value t, col col, f t mut((t, elem))) (col, elem) some
reduce[col, elem] elem option(a col, f elem mut((elem, elem))) (col, elem) some
Returns an empty option if a is empty.
filter[out-col, elem, in-col] out-col(a in-col, f bool mut(elem)) (out-col, elem) list-new, in-col size, (in-col, elem) some
Calls f for each element in the input collection, and returns an output collection of the elements for which f returned true.
omit[out-col, elem, in-col] out-col(a in-col, f bool mut(elem)) (out-col, elem) list-new, in-col size, (in-col, elem) some
Opposite of filter
partition[out-col-false, out-col-true, elem, in-col] (out-col-false, out-col-true)(a in-col, f bool mut(elem)) (out-col-false, elem) list-new, (out-col-true, elem) list-new, in-col size, (in-col, elem) some
Returns a collection of all elements for which f returned false, and another collection for which f returned true.
each[col, elem] void(a col, f void mut(elem)) (col, elem) some
Same as for-loop. For good style, use this only with an it lambda. each xs, it.log is OK, but instead of each xs, of x ..., prefer for x in xs ...
map[out-col, out-elem, in-col, in-elem] out-col(a in-col, f out-elem mut(in-elem)) (out-col, out-elem) list-new, (in-col, in-elem) some, in-col size
Same as for-loop. For good style, use this only with an it lambda. map xs, it.abs is OK, but instead of map xs, of x ..., prefer for x in xs ...
map-optionally[out-col, out-elem, in-col, in-elem] out-col(a in-col, f out-elem option mut(in-elem)) (out-col, out-elem) list-new, (in-col, in-elem) some
Same as for-option. For good style, use this only with an it lambda.
map-every[out-col, out-elem, in-col, in-elem] out-col option(a in-col, f out-elem option mut(in-elem)) (out-col, out-elem) list-new, in-col size, (in-col, in-elem) some
Only returns a result if f returned a non-empty option every time.
map-values[out-col, out-value, in-col, in-value, key] out-col(col in-col, f out-value mut(in-value)) (out-col, (key, out-value)) list-new, (in-col, (key, in-value)) some, in-col size
n-of[col, elem] col(n nat32, value elem) (col, elem) list-new
concatenate[col] spec
~~ col(a col, b col)
repeat[col] col(a col, n nat32) col concatenate, col new
for-option[out-col, out-elem, in-col, in-elem] out-col(a in-col, f out-elem option mut(in-elem)) (out-col, out-elem) list-new, (in-col, in-elem) some
Like for-loop, but f returns an option and empty options are not output.
for-star[out-col, out-elem, in-col, in-elem] out-col(a in-col, f out-elem[] mut(in-elem)) (out-col, out-elem) list-new, (in-col, in-elem) some
Like for-loop, but f must return an array of outputs which are all added to the result.
flat-map[out-col, out-elem, in-col, in-elem] out-col(a in-col, f out-elem[] mut(in-elem)) (out-col, out-elem) list-new, (in-col, in-elem) some
Same as for-star. For good style, use this only with an it lambda.
with-index[col] record
inner col
size[col] nat32(a col with-index) col size
some[col, elem] bool(a col with-index, f bool mut((nat32, elem))) (col, elem) some
with-index8[col] record
inner col
Works like with-index but with a nat8 index.
size[col] nat32(a col with-index8) col size
some[col, elem] bool(a col with-index8, f bool mut((nat8, elem))) (col, elem) some
with-index16[col] record
inner col
Works like with-index but with a nat16 index.
size[col] nat32(a col with-index16) col size
some[col, elem] bool(a col with-index16, f bool mut((nat16, elem))) (col, elem) some
with-is-first[col] record
inner col
size[col] nat32(a col with-is-first) col size
some[col, elem] bool(a col with-is-first, f bool mut((bool, elem))) (col, elem) some
with-is-last[col] record
inner col
size[col] nat32(a col with-is-last) col size
some[col, elem] bool(a col with-is-last, f bool mut((bool, elem))) (col, elem) some
split[out-col, in-col, in-iter, elem] out-col[](a in-col, split-by in-col) (in-col, in-iter, elem) basic-iter, in-iter skip-next-n, (out-col, in-iter) slice, elem equal
count[col, elem] nat32(a col, f bool mut(elem)) (col, elem) some
Calls f on every element and returns the number of times f returned true.
count-while[col, elem] nat32(a col, f bool mut(elem)) (col, elem) some
Like count but stops the first time f returns false.
summable[t] spec t new
+ t(a t, b t)
sum[col, elem] elem(a col) elem summable, (col, elem) some
sum[out, col, elem] out(a col, f out mut(elem)) out summable, (col, elem) some
infinite[t] record
value t
Collection that iterates and returns 'value' forever
infinite void infinite()
some[t] bool(a t infinite, f bool mut(t))
reverse[col] record
inner col
size[col] nat32(a col reverse) col size
some[col, elem] bool(a col reverse, f bool mut(elem)) (col, elem) some-reverse
to[out-col, in-col, elem] out-col(a in-col reverse) (out-col, elem) list-new, in-col size, (in-col, elem) some-reverse
index-of-sequence[col, iter, elem] nat32 option(a col, seq col) (col, iter, elem) basic-iter, iter skip-next-n, elem equal
swap-at[col, elem] void(a col, i nat32, j nat32) (col, elem) buffer-like
swap-at[col, elem] void(a col, i nat32, j index-relative-to-end) (col, elem) buffer-like
swap-at[col, elem] void(a col, i index-relative-to-end, j index-relative-to-end) (col, elem) buffer-like
set-reverse[col, elem] void(a col) (col, elem) buffer-like
fill[col, elem] void(a col, value elem) (col, elem) buffer-like
take-while[out, col, iter, elem] out(a col, f bool mut(elem)) (iter, col) begin, (elem, iter) take-next, iter copy, (out, iter) slice
take-right-while[out, col, iter, elem] out(a col, f bool mut(elem)) (iter, col) end, (elem, iter) take-prev, iter copy, (out, iter) slice
drop-while[out, col, iter, elem] out(a col, f bool mut(elem)) (iter, col) begin, (iter, col) end, (elem, iter) take-next, iter copy, (out, iter) slice
drop-right-while[out, col, iter, elem] out(a col, f bool mut(elem)) (iter, col) begin, (iter, col) end, (elem, iter) take-prev, iter copy, (out, iter) slice
starts-with[col, iter, elem] bool(a col, b col) (col, iter, elem) basic-iter, iter skip-next-n, elem equal
ends-with[col, iter, elem] bool(a col, b col) (col, iter, elem) basic-reverse-iter, iter skip-prev-n, elem equal
try-remove-start[out, col, iter, elem] out option(a col, start col) (col, iter, elem) basic-iter, (iter, col) end, iter skip-next-n, (out, iter) slice, elem equal
try-remove-end[out, col, iter, elem] out option(a col, end col) (col, iter, elem) basic-reverse-iter, (iter, col) begin, iter skip-prev-n, (out, iter) slice, elem equal
strip-left[col, iter, elem] col(a col, b col) (col, iter, elem) basic-iter, (iter, col) end, iter skip-next-n, (col, iter) slice, elem equal
Removes all occurrences of b from the front of a.
strip-right[col, iter, elem] col(a col, b col) (col, iter, elem) basic-reverse-iter, (iter, col) begin, iter skip-prev-n, (col, iter) slice, elem equal
Removes all occurrences of b from the end of a.
contains-seq[col, iter, elem] bool(a col, b col) (col, iter, elem) basic-iter, iter skip-next-n, elem equal

true if b is contained in a.

That means: The elements in b appear in a, in order, without interruptions.

try-split-once[out, col, iter, elem] (out, out) option(a col, b col) (iter, col) end, (col, iter, elem) basic-iter, iter skip-next-n, (out, iter) slice, elem equal

Finds the first appearance of b in a, and returns slices of a to the left and right of that.

Returns an empty option if b is not a subsequence of a.

try-split-once-right[out, col, iter, elem] (out, out) option(a col, b col) (iter, col) begin, (col, iter, elem) basic-reverse-iter, iter skip-prev-n, (out, iter) slice, elem equal
builder[t] record mut (has private fields)
This is an opaque type for pushing values to using ~= or ~~=. This deliberately does not provide any way to access the values. You get a builder by using with out in build where out is the builder.
~=[t] void(a t builder, value t)
~~=[t] void(a t builder, values t array-view)
build-options record
size-hint nat32
build build-options()
build build-options(size-hint nat32)
with-block[col, elem] col(a build-options, f void mut(elem builder)) (col, elem) list-new
build2 record
size-hint0 nat32
size-hint1 nat32
Like build, but builds 2 things at once.
build2 build2()
with-block[col0, elem0, col1, elem1] (col0, col1)(a build2, f void mut((elem0 builder, elem1 builder))) (col0, elem0) list-new, (col1, elem1) list-new
only[col, elem] elem option(a col) col size, (col, elem) some
If the collection has a single element, this is it. Otherwise this is an empty option.
only2[col, elem] (elem, elem) option(a col) col size, (col, elem) some
If the collection has exactly 2 elements, returns them as a tuple. Otherwise this is an empty option.
only3[col, elem] (elem, elem, elem) tuple3 option(a col) col size, (col, elem) some
If the collection has exactly 3 elements, returns them as a tuple. Otherwise this is an empty option.
only4[col, elem] (elem, elem, elem, elem) tuple4 option(a col) col size, (col, elem) some
If the collection has exactly 4 elements, returns them as a tuple.
only5[col, elem] (elem, elem, elem, elem, elem) tuple5 option(a col) col size, (col, elem) some
If the collection has exactly 5 elements, returns them as a tuple.
only6[col, elem] (elem, elem, elem, elem, elem, elem) tuple6 option(a col) col size, (col, elem) some
If the collection has exactly 6 elements, returns them as a tuple.
only7[col, elem] (elem, elem, elem, elem, elem, elem, elem) tuple7 option(a col) col size, (col, elem) some
If the collection has exactly 7 elements, returns them as a tuple.
only8[col, elem] (elem, elem, elem, elem, elem, elem, elem, elem) tuple8 option(a col) col size, (col, elem) some
If the collection has exactly 8 elements, returns them as a tuple.
zip[col0, col1] record
a col0
b col1
size[col0, col1] nat32(a (col0, col1) zip) col0 size, col1 size
some[col0, elem0, col1, elem1] bool(a (col0, col1) zip, f bool mut((elem0, elem1))) (col0, elem0) array-like, (col1, elem1) array-like
some-reverse[col0, elem0, col1, elem1] bool(a (col0, col1) zip, f bool mut((elem0, elem1))) (col0, elem0) array-like, (col1, elem1) array-like
zip-smaller[col0, col1] record
a col0
b col1
Like zip but allows the collections to be different sizes, discarding extra elements.
size[col0, col1] nat32(a (col0, col1) zip-smaller) col0 size, col1 size
some[col0, elem0, col1, elem1] bool(a (col0, col1) zip-smaller, f bool mut((elem0, elem1))) (col0, elem0) array-like, (col1, elem1) array-like
some-reverse[col0, elem0, col1, elem1] bool(a (col0, col1) zip-smaller, f bool mut((elem0, elem1))) (col0, elem0) array-like, (col1, elem1) array-like
all-pairs[t] record
inner t[]
All pairs of different two elements of the array. The element with the lower index always comes first.
size[t] nat32(a t all-pairs)
some[t] bool(a t all-pairs, f bool mut((t, t)))
adjacent-pairs[t] record
inner t[]
(a[0], a[1]), (a[1], a[2]), etc.
size[t] nat32(a t adjacent-pairs)
some[t] bool(a t adjacent-pairs, f bool mut((t, t)))
all-combinations[col0, col1] record
col0 col0
col1 col1
size[col0, col1] nat32(a (col0, col1) all-combinations) col0 size, col1 size
some[col0, elem0, col1, elem1] bool(a (col0, col1) all-combinations, f bool mut((elem0, elem1))) (col0, elem0) some, (col1, elem1) some
indices-where[col, elem] nat32[](a col, f bool mut(elem)) (col, elem) some
only-where[col, elem] elem option(col col, f bool mut(elem)) col size, (col, elem) some
The element satisfying f if it is the only one. If multiple elements satisfy f, this is an empty option, same as if none did.