EsStreamTransformer
Description
Transforms a Stream.
When a stream's #transform method is invoked with an <EsStreamTransformer>, the stream calls the #bind: method on the
provided transformer. The resulting stream is then returned from the #transform: method.
Conceptually, a transformer is simply a function from <EsStream> to <EsStream> that is encapsulated into a class.
It is good practice to write transformers that can be used multiple times.
All other transforming methods on <EsStream>, such as #collect:, #select: or #expand: can be implemented using #transform:. An <EsStreamTransformer> is thus very powerful but often also a bit more complicated to use.
Class Methods
<details> fromBind:
<pre><code> Creates a <EsStreamTransformer> based on a @bind block.
The answered stream transformer uses the @bind argument to implement the
EsStreamTransformer>>bind API and can be used when the transformation is
available as a stream-to-stream method.
Arguments:
bind - <Block> 1-arg with EsStream argument and answers an <EsString>
Answers:
<EsStreamTransformer>
</code></pre> </details>
<details> fromHandlers:handleError:handleDone:
<pre><code> Creates a <EsStreamTransformer> that delegates events to the given block handlers.
Example use of a duplicating transformer:
```
stringStream = EsStream fromCollection: #('hi' 'there').
stringStream transform: (EsStreamTransformer fromHandlers: [:value :sink | sink add: value; add: value] handleError: nil handleDone: nil)
```
Arguments:
handleData - 2-arg Block with Object data, EsEventSink sink.
[:data :sink | <handle data>]
handleError - 3-arg Block with Object error, EsAsyncStackTrace stackTrace, EsEventSink sink.
[:error :stackTrace :sink | <handle error>]
handleDone - 1-arg Block with EsEventSink sink
[:sink | ]
Answers:
<EsStreamTransformer>
</code></pre> </details>
Instance Methods
<details> bind:
<pre><code> Transforms the provided @stream.
Returns a new stream with events that are computed from events of the
provided @stream.
The <EsStreamTransformer> interface is completely generic,
so it cannot say what subclasses do.
Each <EsStreamTransformer> should document clearly how it transforms the
stream (on the class or variable used to access the transformer),
as well as any differences from the following typical behavior:
* When the answered stream is listened to, it starts listening to the
input @stream.
* Subscriptions of the answered stream forward (in a reasonable time)
a EsStreamSubscription>pause] call to the subscription of the input
@stream.
* Similarly, canceling a subscription of the answered stream eventually
(in reasonable time) cancels the subscription of the input @stream.
'Reasonable time' depends on the transformer and stream. Some transformers,
like a 'timeout' transformer, might make these operations depend on a
duration. Others might not delay them at all, or just by a scheduled task.
Transformers are free to handle errors in any way.
A transformer implementation may choose to propagate errors,
or convert them to other events, or ignore them completely,
but if errors are ignored, it should be documented explicitly.
Arguments:
stream - <EsStream>
Answers:
<EsStream>
</code></pre> </details>
Last modified date: 04/21/2022