@@ -145,9 +145,11 @@ module Data.Text.Lazy
145
145
, stripEnd
146
146
, splitAt
147
147
, span
148
+ , spanEnd
148
149
, breakOn
149
150
, breakOnEnd
150
151
, break
152
+ , breakEnd
151
153
, group
152
154
, groupBy
153
155
, inits
@@ -1365,6 +1367,15 @@ break p t0 = break' t0
1365
1367
| otherwise -> let (a,b) = T. splitAt n t
1366
1368
in (Chunk a Empty , Chunk b ts)
1367
1369
1370
+ -- | /O(n)/ Similar to 'break', but searches from the end of the string.
1371
+ --
1372
+ -- >>> T.breakEnd (=='0') "180cm"
1373
+ -- ("180","cm")
1374
+ breakEnd :: (Char -> Bool ) -> Text -> (Text , Text )
1375
+ breakEnd p src = let (a,b) = break p (reverse src)
1376
+ in (reverse b, reverse a)
1377
+ {-# INLINE breakEnd #-}
1378
+
1368
1379
-- | /O(n)/ 'span', applied to a predicate @p@ and text @t@, returns
1369
1380
-- a pair whose first element is the longest prefix (possibly empty)
1370
1381
-- of @t@ of elements that satisfy @p@, and whose second is the
@@ -1376,6 +1387,14 @@ span :: (Char -> Bool) -> Text -> (Text, Text)
1376
1387
span p = break (not . p)
1377
1388
{-# INLINE span #-}
1378
1389
1390
+ -- | /O(n)/ Similar to 'span', but searches from the end of the string.
1391
+ --
1392
+ -- >>> T.spanEnd Data.Char.isAlpha "000AB"
1393
+ -- ("000","AB")
1394
+ spanEnd :: (Char -> Bool ) -> Text -> (Text , Text )
1395
+ spanEnd p = breakEnd (not . p)
1396
+ {-# INLINE spanEnd #-}
1397
+
1379
1398
-- | The 'group' function takes a 'Text' and returns a list of 'Text's
1380
1399
-- such that the concatenation of the result is equal to the argument.
1381
1400
-- Moreover, each sublist in the result contains only equal elements.
0 commit comments