Skip to content

Commit 0998ad0

Browse files
emilypiLysxia
authored andcommitted
parent 1b275ff
author Emily Pillmore <[email protected]> 1578367360 -0500 committer Emily Pillmore <[email protected]> 1612033171 -0500 Add elem combinator to api
1 parent 66bb23b commit 0998ad0

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/Data/Text.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ module Data.Text
185185
, filter
186186
, breakOnAll
187187
, find
188+
, elem
188189
, partition
189190

190191
-- , findSubstring
@@ -1503,6 +1504,13 @@ chunksOf k = go
15031504
-------------------------------------------------------------------------------
15041505
-- ** Searching with a predicate
15051506

1507+
-- | /O(n)/ The 'elem' function takes a character and a 'Text', and
1508+
-- returns 'True' if the element is found in the given 'Text', or
1509+
-- 'False' otherwise.
1510+
elem :: Char -> Text -> Bool
1511+
elem c t = S.any (== c) (stream t)
1512+
{-# INLINE elem #-}
1513+
15061514
-- | /O(n)/ The 'find' function takes a predicate and a 'Text', and
15071515
-- returns the first element matching the predicate, or 'Nothing' if
15081516
-- there is no such element. Subject to fusion.

src/Data/Text/Lazy.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ module Data.Text.Lazy
191191
-- * Searching
192192
, filter
193193
, find
194+
, elem
194195
, breakOnAll
195196
, partition
196197

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

1701+
-- | /O(n)/ The 'elem' function takes a character and a 'Text', and
1702+
-- returns 'True' if the element is found in the given 'Text', or
1703+
-- 'False' otherwise.
1704+
elem :: Char -> Text -> Bool
1705+
elem c t = S.any (== c) (stream t)
1706+
{-# INLINE elem #-}
1707+
17001708
-- | /O(n)/ The 'partition' function takes a predicate and a 'Text',
17011709
-- and returns the pair of 'Text's with elements which do and do not
17021710
-- satisfy the predicate, respectively; i.e.

0 commit comments

Comments
 (0)