#[mixable] Sinkable[T]
Abstract type for values that sinks can be obtained from, whose instances have
the methods below. An Array is Sinkable; a class that only
implements (sink) is not.
Implements: BaseSinkable[T]
Methods
(sink)() -> Sink[T]
Returns a sink that writes to the value.
prechomp() -> Sink[Str] overload 1 of 2
Returns a sink that removes one trailing line terminator (\n or \r\n)
from each value, if present, before writing it.
Parameters
| Name | Type | Description |
|---|---|---|
self |
Sinkable[Str] |
Receiver. |
Errors
Putting a value raises TypeError if it is neither a
Str nor a Bin.
Example
prechomp() -> Sink[Bin] overload 2 of 2
Returns a sink that removes one trailing line terminator (\n or \r\n)
from each value, if present, before writing it.
Parameters
| Name | Type | Description |
|---|---|---|
self |
Sinkable[Bin] |
Receiver. |
Errors
Putting a value raises TypeError if it is neither a
Str nor a Bin.
Example
precrimp … -> Sink[Str] overload 1 of 2
Returns a sink that appends a line terminator to each value before writing it. The append is unconditional, so a value that already ends in one gets a second.
Parameters
| Name | Type | Description |
|---|---|---|
self |
Sinkable[Str] |
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"
precrimp … -> Sink[Bin] overload 2 of 2
Returns a sink that appends a line terminator to each value before writing it. The append is unconditional, so a value that already ends in one gets a second.
Parameters
| Name | Type | Description |
|---|---|---|
self |
Sinkable[Bin] |
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[U @ T] pred -> Sink[U]
Returns a sink that writes only the values for which pred is truthy.
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 |
((U, <Value, >Value) -> Value) |
Example
premap[U] func -> Sink[U]
Returns a sink that transforms each value with func before writing it.
The pre prefix marks the direction: unlike 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, <Value, >Value) -> T) |
Example
put value
Writes a value to the sink.
Parameters
| Name | Type | Description |
|---|---|---|
value |
T |
sink() -> Sink[T]
Returns a sink over the value.