rafa
Version:
Rafa.js is a Javascript framework for building concurrent applications.
31 lines (24 loc) • 746 B
Markdown
Call a mapper that transforms a value into another inner stream for each upstream
message value. All values produced by the inner stream will be emitted to
child streams. Backpressure will not release until the inner stream completes.
<aside>
```js
// flatMap(mapper: A => Stream): Stream
var stream = Rafa.stream();
var values = [];
stream.flatMap(value => {
var inner = Rafa.stream();
var vals = value.split(",");
// defer writing so the returned inner stream can
// be subscribed to beforehand (simplicity for the sake of the example)
setTimeout(() => {
inner.write(vals[0]);
inner.write(vals[1], true);
});
return inner;
})
.each(v => values.push(v));
stream.write("a,b");
// values: ["a", "b"];
```
</aside>