Skip to content

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

Merged
merged 5 commits into from
Nov 24, 2014

Conversation

NightRa
Copy link
Contributor

@NightRa NightRa commented Nov 21, 2014

Added a null,singleton,uncons,takeWhile and dropWhile to Data.String.

I made the takeWhile and dropWhile functions foreign to avoid the unpacking overhead.

var i;
for(i = 0; i < s.length && p(s.charAt(i)); i++){};
return take(i)(s);
}
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Member

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.

@NightRa
Copy link
Contributor Author

NightRa commented Nov 21, 2014

What would be the best way to add foldl/foldr?
Can't add an instance to Foldable as the element is fixed to be Char..

paf31 added a commit that referenced this pull request Nov 24, 2014
Added a null,singleton,uncons,takeWhile and dropWhile to Data.String
@paf31 paf31 merged commit e8d99fd into purescript:master Nov 24, 2014
@paf31
Copy link
Contributor

paf31 commented Nov 24, 2014

Thanks!

I think foldl/r can be added as standalone functions (without an instance).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants