Skip to content

Commit c0b11ac

Browse files
LysxiaBodigrim
authored andcommitted
Add spanEnd
1 parent 4142530 commit c0b11ac

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/Data/Text.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ module Data.Text
159159
, break
160160
, span
161161
, spanM
162+
, spanEnd
162163
, spanEndM
163164
, group
164165
, groupBy
@@ -243,6 +244,8 @@ import qualified Data.List as L hiding (head, tail)
243244
import qualified Data.List.NonEmpty as NonEmptyList
244245
import Data.Binary (Binary(get, put))
245246
import Data.Binary.Put (putBuilder)
247+
import Data.Coerce (coerce)
248+
import Data.Functor.Identity (Identity(..))
246249
import Data.Monoid (Monoid(..))
247250
import Data.Semigroup (Semigroup(..))
248251
import Data.String (IsString(..))
@@ -1623,6 +1626,9 @@ break :: (Char -> Bool) -> Text -> (Text, Text)
16231626
break p = span (not . p)
16241627
{-# INLINE break #-}
16251628

1629+
spanEnd :: (Char -> Bool) -> Text -> (Text, Text)
1630+
spanEnd = coerce (spanEndM :: (Char -> Identity Bool) -> Text -> Identity (Text, Text))
1631+
16261632
-- | /O(length of prefix)/ 'spanM', applied to a monadic predicate @p@,
16271633
-- a text @t@, returns a pair @(t1, t2)@ where @t1@ is the longest prefix of
16281634
-- @t@ whose elements satisfy @p@, and @t2@ is the remainder of the text.

0 commit comments

Comments
 (0)