chrislusf/glow

Is there a means of teeing the flow?

Closed this issue · 3 comments

This isn't a great example but I'm looking for a way to do something like this:

stream := flow.New().Source(source, parts).Map(mapper)
flow_a, flow_b := stream.Tee() // <-- this is what i really want
go flow_a.Filter(a_filter).
  Reduce(a_reduce).
  Run()
flow_a.Filter(b_filter).
  Reduce(b_reduce).
  Run()

basically, I want to be able to filter the same stream multiple ways without iterating the stream multiple times.

@nicerobot As a workaround you may create a channel, then add a Map() to the first stream flow that would return element as is and also write that element to your channel. Now make another flow with a Source() function reading from your channel and write incoming elements to your output channel.
I haven't tried it yet, so I don't know if it will make things slower or not.

@zserge Thanks. Yea, I ended up with that solution. But I was just wondering if there was something native to the library that I was overlooking.

I am not remembering the details of glow now. Please use gleam. It also has a pure go support and can directly support this Tee().