Skip to content

Commit d4397a7

Browse files
committed
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.
1 parent fdd4285 commit d4397a7

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

src/Data/Text.hs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,7 @@ import qualified Language.Haskell.TH.Lib as TH
253253
import qualified Language.Haskell.TH.Syntax as TH
254254
import Text.Printf (PrintfArg, formatArg, formatString)
255255
import System.Posix.Types (CSsize(..))
256-
import Data.Maybe (maybe)
257-
import Data.Bool (bool)
256+
import Data.Function (on)
258257

259258
-- $setup
260259
-- >>> import Data.Text
@@ -1892,21 +1891,16 @@ isSubsequenceOf tf sf
18921891
where
18931892
subseqOf :: Text -> Text -> Bool
18941893
subseqOf t s =
1895-
maybe
1896-
True
1897-
(\ (sc,ss) ->
1898-
maybe
1899-
False
1900-
(\ (tc,ts) ->
1901-
subseqOf ts $
1902-
bool
1903-
s
1904-
ss
1905-
(sc /= tc)
1906-
)
1907-
(uncons t)
1908-
)
1909-
(uncons s)
1894+
on f uncons s t
1895+
where
1896+
f :: Maybe (Char, Text) -> Maybe (Char, Text) -> Bool
1897+
f Nothing _ = True
1898+
f _ Nothing = False
1899+
f (Just (sc,ss)) (Just (tc,ts)) =
1900+
subseqOf ts $
1901+
if sc == tc
1902+
then s
1903+
else ss
19101904

19111905
-------------------------------------------------------------------------------
19121906
-- * View patterns

0 commit comments

Comments
 (0)