poelstra / ts-stream

Type-safe object streams with seamless support for backpressure, ending, and error handling
MIT License
65 stars 13 forks source link

Cosmetics: please return the stream from forEach() to facilitate nicer-looking code #11

Closed rogierschouten closed 9 years ago

rogierschouten commented 9 years ago

Now that forEach doesn't return a promise (for good reasons), it can maybe return the stream itself. This would facilitate the following code pattern:

var stream = getStreamSomehow()
        .transform(mytransform)
        .map(mymapper)
        .forEach(dosomething);
return stream.ended();

Currently, I have to write:

var stream = getStreamSomehow()
        .transform(mytransform)
        .map(mymapper);
stream.forEach(dosomething);
return stream.ended();

which breaks the natural flow a bit.

poelstra commented 9 years ago

Actually, now that ended() can return the 'source' stream's end result, and the result of ended() IS actually handled (because it is passed to the next stream's end()), both concerns of #2 are no longer an issue.

So I was already thinking about returning ended() from forEach() now.

poelstra commented 9 years ago

Implemented in 0.6.0: forEach() now returns result() (which is the renamed ended(), mentioned above).