STRUCT
Sink
¶
public struct Sink<Value>
Sink is a type that receives incoming values (commonly events or WorkflowAction
)
Use RenderContext.makeSink
to create instances.
Methods¶
init(_:)
¶
public init(_ onValue: @escaping (Value) -> Void)
Initializes a new sink with the given closure.
send(_:)
¶
public func send(_ value: Value)
Sends a new event into the sink.
- Parameter event: The value to send into the sink.
Parameters¶
Name | Description |
---|---|
event | The value to send into the sink. |
contraMap(_:)
¶
public func contraMap<NewValue>(_ transform: @escaping (NewValue) -> Value) -> Sink<NewValue>
Generates a new sink of type NewValue.
Given a transform
closure, the following code is functionally equivalent:
sink.send(transform(value))
sink.contraMap(transform).send(value)
Trivia: Why is this called contraMap
?
- map
turns Type<T>
into Type<U>
via (T)->U
.
- contraMap
turns Type<T>
into Type<U>
via (U)->T
Another way to think about this is: map
transforms a type by changing the
output types of its API, while contraMap
transforms a type by changing the
input types of its API.
- Parameter transform: An escaping closure that transforms
T
intoEvent
.
Parameters¶
Name | Description |
---|---|
transform | An escaping closure that transforms T into Event . |