@@ -157,9 +157,11 @@ module Data.Text.Lazy
157
157
, stripEnd
158
158
, splitAt
159
159
, span
160
+ , spanEnd
160
161
, breakOn
161
162
, breakOnEnd
162
163
, break
164
+ , breakEnd
163
165
, group
164
166
, groupBy
165
167
, inits
@@ -1404,6 +1406,15 @@ break p t0 = break' t0
1404
1406
| otherwise -> let (a,b) = T. splitAt n t
1405
1407
in (Chunk a Empty , Chunk b ts)
1406
1408
1409
+ -- | /O(n)/ Similar to 'break', but searches from the end of the string.
1410
+ --
1411
+ -- >>> T.breakEnd (=='0') "180cm"
1412
+ -- ("180","cm")
1413
+ breakEnd :: (Char -> Bool ) -> Text -> (Text , Text )
1414
+ breakEnd p src = let (a,b) = break p (reverse src)
1415
+ in (reverse b, reverse a)
1416
+ {-# INLINE breakEnd #-}
1417
+
1407
1418
-- | /O(n)/ 'span', applied to a predicate @p@ and text @t@, returns
1408
1419
-- a pair whose first element is the longest prefix (possibly empty)
1409
1420
-- of @t@ of elements that satisfy @p@, and whose second is the
@@ -1415,6 +1426,14 @@ span :: (Char -> Bool) -> Text -> (Text, Text)
1415
1426
span p = break (not . p)
1416
1427
{-# INLINE span #-}
1417
1428
1429
+ -- | /O(n)/ Similar to 'span', but searches from the end of the string.
1430
+ --
1431
+ -- >>> T.spanEnd Data.Char.isAlpha "000AB"
1432
+ -- ("000","AB")
1433
+ spanEnd :: (Char -> Bool ) -> Text -> (Text , Text )
1434
+ spanEnd p = breakEnd (not . p)
1435
+ {-# INLINE spanEnd #-}
1436
+
1418
1437
-- | The 'group' function takes a 'Text' and returns a list of 'Text's
1419
1438
-- such that the concatenation of the result is equal to the argument.
1420
1439
-- Moreover, each sublist in the result contains only equal elements.
0 commit comments