Skip to content

Instantly share code, notes, and snippets.

@yelouafi
Created July 17, 2015 02:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yelouafi/e0bb90f3218c60a24b3e to your computer and use it in GitHub Desktop.
Save yelouafi/e0bb90f3218c60a24b3e to your computer and use it in GitHub Desktop.
// flatten : ( Stream (Stream a), (Stream a, Stream a) -> Stream a) -> Stream a
Stream.prototype.flatten = function(f) {
return this.isEmpty || this.isAbort ? this
: this.isCons ? f( this.head, this.tail.flatten(f) )
: Stream.Future(this.promise.then(s => s.flatten(f), Stream.Abort));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment