From 0998ad09e8ef566a5d6f2a69144b212ad3107bd6 Mon Sep 17 00:00:00 2001 From: Emily Pillmore Date: Mon, 6 Jan 2020 22:22:40 -0500 Subject: [PATCH] parent 1b275ff7e2050835eefbf4df6e17952628a11e72 author Emily Pillmore 1578367360 -0500 committer Emily Pillmore 1612033171 -0500 Add elem combinator to api --- src/Data/Text.hs | 8 ++++++++ src/Data/Text/Lazy.hs | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/Data/Text.hs b/src/Data/Text.hs index 0734cbaf..a0751171 100644 --- a/src/Data/Text.hs +++ b/src/Data/Text.hs @@ -185,6 +185,7 @@ module Data.Text , filter , breakOnAll , find + , elem , partition -- , findSubstring @@ -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. diff --git a/src/Data/Text/Lazy.hs b/src/Data/Text/Lazy.hs index c974c979..ad4b7e62 100644 --- a/src/Data/Text/Lazy.hs +++ b/src/Data/Text/Lazy.hs @@ -191,6 +191,7 @@ module Data.Text.Lazy -- * Searching , filter , find + , elem , breakOnAll , partition @@ -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.