Skip to content

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

Merged
paf31 merged 5 commits into
purescript:masterfrom
NightRa:master
Nov 24, 2014
Merged

Added a null,singleton,uncons,takeWhile and dropWhile to Data.String#18
paf31 merged 5 commits into
purescript:masterfrom
NightRa:master

Conversation

@NightRa
Copy link
Copy Markdown
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.

Comment thread src/Data/String.purs Outdated
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread src/Data/String.purs Outdated
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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