From d4397a72ddb0beffecbde3175e8bc2c20bba4f66 Mon Sep 17 00:00:00 2001 From: Anton-Latukha Date: Tue, 28 Sep 2021 12:51:45 +0300 Subject: [PATCH] WIP: Text: isSubsequenceOf: lambda to imperative `on` now ensures that `uncons` can be specialized/consumed once. It would be interesting to look into Core at some point of work. --- src/Data/Text.hs | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/Data/Text.hs b/src/Data/Text.hs index 35cf3296..f30c54d6 100644 --- a/src/Data/Text.hs +++ b/src/Data/Text.hs @@ -253,8 +253,7 @@ import qualified Language.Haskell.TH.Lib as TH import qualified Language.Haskell.TH.Syntax as TH import Text.Printf (PrintfArg, formatArg, formatString) import System.Posix.Types (CSsize(..)) -import Data.Maybe (maybe) -import Data.Bool (bool) +import Data.Function (on) -- $setup -- >>> import Data.Text @@ -1892,21 +1891,16 @@ isSubsequenceOf tf sf where subseqOf :: Text -> Text -> Bool subseqOf t s = - maybe - True - (\ (sc,ss) -> - maybe - False - (\ (tc,ts) -> - subseqOf ts $ - bool - s - ss - (sc /= tc) - ) - (uncons t) - ) - (uncons s) + on f uncons s t + where + f :: Maybe (Char, Text) -> Maybe (Char, Text) -> Bool + f Nothing _ = True + f _ Nothing = False + f (Just (sc,ss)) (Just (tc,ts)) = + subseqOf ts $ + if sc == tc + then s + else ss ------------------------------------------------------------------------------- -- * View patterns