Skip to content

Instantly share code, notes, and snippets.

@yelouafi yelouafi/stream-foreach.js
Last active Aug 29, 2015

Embed
What would you like to do?
const noop = () => {}
Stream.prototype.forEach = function(onNext, onError=noop, onComplete=noop) {
return this.isEmpty ? onComplete()
: this.isAbort ? onError(this.error) :
: this.isCons ? (
onNext(this.head),
this.tail.forEach(onNext, onError, onComplete))
: this.promise.then(
stream => stream.forEach(onNext, onError, onComplete),
onError);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.