Skip to content

Commit

Permalink
parent 1b275ff
Browse files Browse the repository at this point in the history
author Emily Pillmore <emily@kadena.io> 1578367360 -0500
committer Emily Pillmore <emilypi@cohomolo.gy> 1612033171 -0500

Add elem combinator to api
  • Loading branch information
emilypi authored and Lysxia committed Mar 20, 2021
1 parent 66bb23b commit 0998ad0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Data/Text.hs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ module Data.Text
, filter
, breakOnAll
, find
, elem
, partition

-- , findSubstring
Expand Down Expand Up @@ -1503,6 +1504,13 @@ chunksOf k = go
-------------------------------------------------------------------------------
-- ** Searching with a predicate

-- | /O(n)/ The 'elem' function takes a character and a 'Text', and
-- returns 'True' if the element is found in the given 'Text', or
-- 'False' otherwise.
elem :: Char -> Text -> Bool
elem c t = S.any (== c) (stream t)
{-# INLINE elem #-}

-- | /O(n)/ The 'find' function takes a predicate and a 'Text', and
-- returns the first element matching the predicate, or 'Nothing' if
-- there is no such element. Subject to fusion.
Expand Down
8 changes: 8 additions & 0 deletions src/Data/Text/Lazy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ module Data.Text.Lazy
-- * Searching
, filter
, find
, elem
, breakOnAll
, partition

Expand Down Expand Up @@ -1697,6 +1698,13 @@ find :: (Char -> Bool) -> Text -> Maybe Char
find p t = S.findBy p (stream t)
{-# INLINE find #-}

-- | /O(n)/ The 'elem' function takes a character and a 'Text', and
-- returns 'True' if the element is found in the given 'Text', or
-- 'False' otherwise.
elem :: Char -> Text -> Bool
elem c t = S.any (== c) (stream t)
{-# INLINE elem #-}

-- | /O(n)/ The 'partition' function takes a predicate and a 'Text',
-- and returns the pair of 'Text's with elements which do and do not
-- satisfy the predicate, respectively; i.e.
Expand Down

0 comments on commit 0998ad0

Please sign in to comment.