Sink[T]
Abstract type for sinks, whose instances have the methods below. Built-in
sinks are Sink; a class that only implements (put) is not.
Sink is not constructible directly.
Inherits from: Sinkable[T]
Implements: BaseSink[T]
Methods
prechomp[U @ (Str | Bin)]() -> Sink[U]
Creates a wrapper Sink which removes a trailing line terminator (\n or
\r\n) from each item, if present, before it is written.
Parameters
| Name | Type | Description |
|---|---|---|
self |
Sink[U] |
Receiver. |
Errors
Putting an item raises TypeError if it is neither
neither a Str nor a Bin.
Example
precrimp[U @ (Str | Bin)] … -> Sink[U]
Creates a wrapper Sink that appends a terminator to each value before it is
written. The append is unconditional, so an item that already ends in one gets
a second.
Parameters
| Name | Type | Description |
|---|---|---|
self |
Sink[U] |
Receiver. |
terminator? |
(Str | Bin) |
Errors
Raises TypeError for a value, or a terminator, that is
neither a Str nor a Bin, or if a Bin terminator would leave a Str value
invalid UTF-8.
Example
let out = shell.stdout.precrimp()
out.put "hello"
# writes "hello\n"
open $path w do |file|
file.precrimp(shell.line_ending()).put "native"
prefilter pred -> Sink[T]
Wraps the sink so only values for which pred is truthy are written.
Because each wrapper transforms values on the way in, the outermost wrapper sees a value first — the reverse of an iterator chain.
Parameters
| Name | Type | Description |
|---|---|---|
pred |
((T) -> Value) |
Example
premap[U] func -> Sink[U]
Wraps the sink so each value is transformed before it is written.
The pre prefix marks the direction: unlike Iter.map,
which transforms values on their way out, premap transforms values on their
way into the sink. A value that is both Iterable and
Sinkable — an Array, say — therefore offers
map and premap as separate methods running in opposite directions.
Parameters
| Name | Type | Description |
|---|---|---|
func |
((U) -> T) |
Example
put value
Writes a value to the sink.
Parameters
| Name | Type | Description |
|---|---|---|
value |
T |