datastream/chunk
Chunk(a) is an opaque, finite, immutable batch of elements.
Chunks are the element type of stream operations that produce
batches (stream.chunks_of, stream.group_adjacent,
erlang/time.window_time, …). The type is intentionally opaque so
the internal representation can change later (for example a
contiguous byte buffer for Chunk(Int)) without breaking callers.
The accessor surface is intentionally narrow: to_list, size,
is_empty. Anything else is expressed by going through to_list,
keeping Chunk from re-mirroring the entire list API.
Chunks are finite by design. Infinite-ness is the responsibility
of Stream, not of a self-contained value.
Types
Values
pub fn filter(
over chunk: Chunk(a),
keeping predicate: fn(a) -> Bool,
) -> Chunk(a)
Keep only the elements for which predicate returns True. Order
is preserved.
pub fn from_list(elements: List(a)) -> Chunk(a)
Build a chunk from a list of elements.
Round-trips with to_list: to_list(from_list(xs)) == xs.
pub fn map(over chunk: Chunk(a), with f: fn(a) -> b) -> Chunk(b)
Apply f to every element. The result has the same size as the
input; order is preserved.
pub fn size(chunk: Chunk(a)) -> Int
Number of elements in chunk. O(n) in the current implementation
(the chunk’s element list is walked).