-
Notifications
You must be signed in to change notification settings - Fork 72
Added a null,singleton,uncons,takeWhile and dropWhile to Data.String #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
var i; | ||
for(i = 0; i < s.length && p(s.charAt(i)); i++){}; | ||
return take(i)(s); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line should have a semicolon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't know that semicolons are nessesary after function definitions in JS. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Semicolons are not necessary in most cases, due to automatic semicolon insertion, but we might as well output "correct" code. Also, to clarify, a function statement (as used to define takeWhile
above, for example) should not be terminated by a semicolon, whereas a function expression (as used to define the return value of takeWhile
) should be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Purescript seems to generate semicolons after foreign function statements anyway.
return function(s){ | ||
var i; | ||
for(i = 0; i < s.length && p(s.charAt(i)); i++){}; | ||
return drop(i)(s); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These will not work with dead code elimination turned on. drop
might be removed. It would be better to pass a reference to the drop function as a function argument. The same applies to takeWhile
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better than that might be to just slice
it.
What would be the best way to add foldl/foldr? |
Added a null,singleton,uncons,takeWhile and dropWhile to Data.String
Thanks! I think |
Added a null,singleton,uncons,takeWhile and dropWhile to Data.String.
I made the takeWhile and dropWhile functions foreign to avoid the unpacking overhead.