highland icon indicating copy to clipboard operation
highland copied to clipboard

FlatTap

Open irony opened this issue 8 years ago • 2 comments

When dealing with promises it would be nice to be able to do a stream.flatTap(_(save)) which would disregard the output but wait for the promise to resolve. (shorthand for stream.flatMap(item => _(save(item).then(() => item)))

irony avatar Apr 20 '17 21:04 irony

I guess I wouldn't mind adding something like this since we already have tap, but it would work with streams, not promises. Highland isn't a promises library, so the only direct integration point with promises is the constructor.

So stream.flatTap(save) would be shorthand for stream.flatMap(item => save(item).filter(() => false).append(item)), where save returns a Highland stream. Which means, when working with promises, you'd still have to do stream.flatTap(item => _(save(item))). At that point, I'm not sure it's saving you much at all.

But if you want to submit a PR, I'll accept it.

vqvu avatar Apr 21 '17 00:04 vqvu

I also agree this could be useful - we use this a lot in our codebase for varying reasons.

Made a PR: https://github.com/caolan/highland/pull/651

tomwhale avatar Jul 04 '18 09:07 tomwhale