Data and Math
vseq
Windows, chunks, deduplication, partitions and run length coding for whole sequences.
Released v1.0.0 · 2026-09-28use "stdlib/seq.ven"
print windows([1, 2, 3, 4], 2)
:: [[1, 2], [2, 3], [3, 4]]
Reference (15 functions)
API reference
windows(items, size)
Slices items into every overlapping run of size consecutive elements.
windows([1, 2, 3, 4], 2)
:: gives [[1, 2], [2, 3], [3, 4]]chunks(items, size)
Splits items into consecutive, non-overlapping runs of size elements.
chunks([1, 2, 3, 4, 5], 2)
:: gives [[1, 2], [3, 4], [5]]flattened(items, depth)
Flattens nested Lists inside items up to depth levels deep.
flattened([1, [2, [3, 4]], 5], 1)
:: gives [1, 2, [3, 4], 5]unique(items)
Gives back items with duplicate values removed, keeping first occurrences in order.
unique([1, 2, 2, 3, 1])
:: gives [1, 2, 3]unique_by(items, key_fn)
Gives back items with duplicate keys removed, keeping the first item per key.
make parity(x)
give x % 2
unique_by([4, 1, 6, 3], parity)
:: gives [4, 1]partition(items, predicate)
Splits items into a (matching, non_matching) pair by predicate.
make is_even(x)
give x % 2 == 0
partition([1, 2, 3, 4, 5, 6], is_even)
:: gives ([2, 4, 6], [1, 3, 5])group_by(items, key_fn)
Groups items into a Map of key to the List of items sharing that key.
make is_even(x)
give x % 2 == 0
group_by([1, 2, 3, 4, 5], is_even)
:: gives {no: [1, 3, 5], yes: [2, 4]}scan(items, seed, fn)
Gives back every running total fn produces while folding items from seed.
make add(a, b)
give a + b
scan([1, 2, 3, 4], 0, add)
:: gives [1, 3, 6, 10]pairwise(items)
Pairs up consecutive elements of items: [a, b, c, d] becomes [(a, b), (b, c), (c, d)].
pairwise([1, 2, 3, 4])
:: gives [(1, 2), (2, 3), (3, 4)]rotated(items, n)
Rotates items left by n positions: the first n elements move to the end, in order.
rotated([1, 2, 3, 4, 5], 2)
:: gives [3, 4, 5, 1, 2]take_while(items, predicate)
Takes elements from the front of items up to, but not including, the first one where predicate returns falsy.
make less_than_3(x)
give x < 3
take_while([1, 2, 3, 4, 1], less_than_3)
:: gives [1, 2]drop_while(items, predicate)
Drops elements from the front of items up to, but not including, the first one where predicate returns falsy, and returns the rest.
make less_than_3(x)
give x < 3
drop_while([1, 2, 3, 4, 1], less_than_3)
:: gives [3, 4, 1]interleaved(lists)
Interleaves several Lists round-robin: the first element of each List, then the second element of each, and so on.
interleaved([[1, 2, 3], [10, 20]])
:: gives [1, 10, 2, 20, 3]run_length_encode(items)
Run-length encodes items: each run of consecutive equal elements becomes one (value, count) Tuple.
run_length_encode([1, 1, 1, 2, 2, 3])
:: gives [(1, 3), (2, 2), (3, 1)]run_length_decode(pairs)
Inverse of run_length_encode: expands (value, count) pairs back into a flat List.
run_length_decode([(1, 3), (2, 2), (3, 1)])
:: gives [1, 1, 1, 2, 2, 3]