it-pipe
Utility to "pipe" async iterables together
Based on this definition of streaming iterables https://gist.github.com/alanshaw/591dc7dd54e4f99338a347ef568d6ee9.
Almost identical to the pipeline
function from the streaming-iterables
module except that it supports duplex streams and will automatically wrap a "source" as the first param in a function.
Install
npm i it-pipe
Usage
import { pipe } from 'it-pipe'
const result = await pipe(
[1, 2, 3],
function transform (source) {
return (async function * () {
for await (const val of source) yield val * 2
})()
},
async function collect (source) {
const vals = []
for await (const val of source) {
vals.push(val)
}
return vals
}
)
console.log(result)
API
pipe(firstFn, ...fns)
Calls firstFn
and then every function in fns
with the result of the previous function. The final return is the result of the last function in fns
.
Note:
firstFn
may be a Function
or an Iterable
firstFn
or any of fns
may be a duplex object (an object with a sink
and source
).
Contribute
Feel free to dive in! Open an issue or submit PRs.
License
MIT © Alan Shaw