text
text copied to clipboard
Add spanEnd and breakEnd to Data.Text
Provides part of #244 for Data.Text.
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 Data.Text.Lazy - while I guess that doesn't really matter for this specific PR, it means that #244 isn't technically fully resolved. I can try to add those if you're interested, but I imagine they are going to be slightly less trivial because of list-like nature of lazy Text.
Looking at breakOnEnd, would similar implementation using reverse make sense? I'm not familiar enough with performance characteristics of text to tell whether it would break existing optimizations.
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 #-}
, spanEnd inmplemented in terms of it, and some fixes of whitespace in spanEnd_.
Would any other @haskell/text maintainers like to chime in?
@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 https://github.com/haskell/text/blob/0998ad09e8ef566a5d6f2a69144b212ad3107bd6/tests/Tests/Properties.hs#L621-L622
Thanks. I didn't realize we could (and were already) using Data.List as a reference implementation for property testing.
@Bodigrim no problem. Should I include mentioned Lazy versions too?
Yeah, it would be nice.
Ping.
- Add tests.
- (optional) Add lazy versions.
Oops, sorry, I forgot to upload changes - will do so today.
Should I rebase it on current master?
Yes please :)
I've rebased on top of current master.