Skip to content

Instantly share code, notes, and snippets.

@yelouafi
Last active August 29, 2015 14:25
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/9986872d708ccbf57e2b to your computer and use it in GitHub Desktop.
Save yelouafi/9986872d708ccbf57e2b to your computer and use it in GitHub Desktop.
// groupBy : (Stream a, (a, a) -> aBoolean) => Stream (Stream a)
Stream.prototype.groupBy = function(p) {
var s1, s2;
return this.isEmpty || this.isAbort ? this
: this.isCons ?
( [s1, s2] = this.tail.span( x => p(this.head, x) ),
Stream.Cons(
Stream.Cons(this.head, s1),
s2.groupBy(p)))
: Stream.Future( this.promise.then( s => s.groupBy(p), Stream.Abort ) );
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment