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 ); | |
} |
- I am not sure how would be better but now that I am thinking bout it Haskell does exactly the same.
- 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
That's a very nice idea — thank you. I have two suggestions before this can be merged:
Otherwise great job! Thanks :)