-
Notifications
You must be signed in to change notification settings - Fork 157
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 spanEnd and breakEnd to Data.Text #312
base: master
Are you sure you want to change the base?
Conversation
This looks good to me. Would any other @haskell/text maintainers like to chime in? Let's merge this with one more approval. This PR seems to actually close #244, or did I miss something else in that issue? |
It doesn't actually add corresponding functions to |
Looking at |
I've locally prepared commit with -- | /O(n)/ Similar to 'break', but searches from the end of the string.
--
-- >>> T.breakEnd (=='0') "180cm"
-- ("180","cm")
breakEnd :: (Char -> Bool) -> Text -> (Text, Text)
breakEnd p src = let (a,b) = break p (reverse src)
in (reverse b, reverse a)
{-# INLINE breakEnd #-} , |
@Lysxia you can request reviews from other maintainers, adding them under the gear in the top right corner of "Reviewers" panel. |
@TheMatten would it be possible to add tests for new functions? |
@Bodigrim Where would be a good place to add such tests? There doesn't seem to be a unit-testing suite, is there? It might be good to document this somewhere too. |
@Lysxia I suggest adding tests somewhere near text/tests/Tests/Properties.hs Lines 621 to 622 in 0998ad0
|
Thanks. I didn't realize we could (and were already) using |
@Bodigrim no problem. Should I include mentioned |
Yeah, it would be nice. |
Ping.
|
Oops, sorry, I forgot to upload changes - will do so today. |
Should I rebase it on current master? |
Yes please :) |
src/Data/Text/Lazy.hs
Outdated
-- >>> T.breakEnd (=='0') "180cm" | ||
-- ("180","cm") | ||
breakEnd :: (Char -> Bool) -> Text -> (Text, Text) | ||
breakEnd p src = let (a,b) = break p (reverse src) |
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.
I'm afraid that reversing is very expensive and annihilates all benefits of lazy Text
. Would it be possible to have something lazier?
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.
You mean something that wouldn't touch chunk contents on left side of text being broken?
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.
See c76b9aa
I've rebased on top of current |
go r Empty = (empty, r) | ||
go r (Chunk t ts) = case T.breakEnd p t of | ||
("", _) -> go (Chunk t r) ts | ||
(l, r') -> (reverseSpine (Chunk l ts), Chunk r' r) |
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.
Looks good, but please do not enable OverloadedStrings
in this module.
Would it be possible to implement via foldrChunks
? Something like
breakEnd :: (Char -> Bool) -> Text -> (Text, Text)
breakEnd p = foldrChunks go (empty, empty)
where
go x (ys, zs)
| null ys = let (y, z) = T.breakEnd p x in (chunk y empty, chunk z zs)
| otherwise = (chunk x ys, zs)
Provides part of #244 for
Data.Text
.