Skip to content

Commit

Permalink
WIP: Text: isSubsequenceOf: lambda to imperative
Browse files Browse the repository at this point in the history
`on` now ensures that `uncons` can be specialized/consumed once.

It would be interesting to look into Core at some point of work.
  • Loading branch information
Anton-Latukha committed Sep 28, 2021
1 parent fdd4285 commit d4397a7
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions src/Data/Text.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d4397a7

Please sign in to comment.