Skip to content

Instantly share code, notes, and snippets.

@trigeorgis
Created September 12, 2011 12:33
Show Gist options
  • Save trigeorgis/1211149 to your computer and use it in GitHub Desktop.
Save trigeorgis/1211149 to your computer and use it in GitHub Desktop.
Stream.js addition
drop: function(howmany){
if ( howmany <= 0 ) {
if ( this.empty() ) {
return new Stream();
}
return new Stream( this.head(), this.tail() );
}
// Otherwise we could check only once if it's empty and omit the exception.
if ( this.empty() ) {
throw 'You want to drop too many items.';
}
return this.tail().drop( howmany - 1 );
}
@trigeorgis
Copy link
Author

  1. I am not sure how would be better but now that I am thinking bout it Haskell does exactly the same.
  2. Yeap you are right, did not notice that you have the js on github till later on.

I will fork it and make the changes ;) Whats next, maybe http://haskell.org/ghc/docs/latest/html/libraries/base/Data-List.html ? :p

Great idea and job as well! ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment