Created
September 12, 2011 12:33
-
-
Save trigeorgis/1211149 to your computer and use it in GitHub Desktop.
Stream.js addition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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! ;)