-
Notifications
You must be signed in to change notification settings - Fork 73
add slice #104
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
add slice #104
Conversation
src/Data/String.purs
Outdated
-- | Returns the substring at indices [begin, end). | ||
-- | If either index is negative, it is normalized to `length s - index`, | ||
-- | where `s` is the input string. An empty string is returned if either | ||
-- | index is out of bounds or if `begin > end`. |
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.
Might want to say "or if begin > end
after normalisation".
I don't like the empty string being used as the error case. What else can we do? |
Agreed. That is the default behaviour for javascript, but I could wrap the result in a |
I don't know if this is better. This implementation doesn't check for the bounds, it just returns |
Feel free to copy code from the implementation of |
This is (necessarily) confusing code. It deserves some tests. ;) |
The length calculations and bounds checking can be done in pure code. We should try to minimise the amount of JS. Basically, it should just expose |
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.
LGTM. Let's also add exhaustive tests for each of the cases that could produce Nothing
.
Ping @themattchan. With only a few added tests, we can land this PR. |
Ok, I think the new tests exercise all the error conditions. |
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.
💯 Thanks @themattchan! LGTM.
Thanks all! |
No description provided.