Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Piping through to a new stream #687

Open
srcnix opened this issue Nov 17, 2019 · 1 comment
Open

Piping through to a new stream #687

srcnix opened this issue Nov 17, 2019 · 1 comment

Comments

@srcnix
Copy link

srcnix commented Nov 17, 2019

First of all, awesome library you have built!

I'm trying to wrap my head around a few things, and currently looking at being able to setup a stream, and then pipe the data from the stream into another (which may go through X number of other streams).

These streams would further filter, or do some magic, run some async code etc.

What's the best way to do this?

@amsross
Copy link
Contributor

amsross commented Nov 19, 2019

Do you have a more specific example that you could provide regarding what you're trying to do?

Barring that, here is some generic example code you might be able to extract some meaning from:

const source = _([ 1, 2, 3, 4 ])

const addOne = _.map(x => x + 1)
const filterEvens = _.filter(x => x % 2 === 0)
const asyncStuff = _.flatMap(x => _((push, next) => setTimeout(() => {
  push(null, x)
  push(null, _.nil)
}, 1000)))

const doStuff = _.pipeline(addOne, filterEvens, asyncStuff)

source
  .through(doStuff)
  .each(_.log) // this could just as well be `.pipe(someNodeStream)`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants