Skip to content

Sinkable

Abstract type for values that implement the (sink) protocol. Sinkable values can be converted into sinks explicitly and used for type testing.

Sinkable is not constructible directly.

assert (type [] Sinkable)

Methods

sink

Returns a sink over the value.

Returns

Sink

Forwarded methods

x.foo(...) on a Sinkable means x.sink().foo(...), so Sink's methods can be called on the value directly:

Method Description
put value Writes a value
premap func Transforms each value before it is written
prefilter pred Writes only values for which pred is truthy

premap/prefilter are named for their direction — they act on values headed into the sink. A value that is both Sinkable and Iterable, such as an Array, offers those alongside map/filter, which run the opposite way:

let acc = []
let out = acc.premap (do |x| x * 2)
out.put 3
assert_eq $acc [6]
assert_eq [...acc.map (do |x| x + 1)] [7]