Skip to content

Commit f477ba6

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 173c1ae commit f477ba6

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
@@ -254,8 +254,7 @@ import qualified Language.Haskell.TH.Lib as TH
254254
import qualified Language.Haskell.TH.Syntax as TH
255255
import Text.Printf (PrintfArg, formatArg, formatString)
256256
import System.Posix.Types (CSsize(..))
257-
import Data.Maybe (maybe)
258-
import Data.Bool (bool)
257+
import Data.Function (on)
259258

260259
-- $setup
261260
-- >>> import Data.Text
@@ -1896,21 +1895,16 @@ isSubsequenceOf tf sf
18961895
where
18971896
subseqOf :: Text -> Text -> Bool
18981897
subseqOf t s =
1899-
maybe
1900-
True
1901-
(\ (sc,ss) ->
1902-
maybe
1903-
False
1904-
(\ (tc,ts) ->
1905-
subseqOf ts $
1906-
bool
1907-
s
1908-
ss
1909-
(sc /= tc)
1910-
)
1911-
(uncons t)
1912-
)
1913-
(uncons s)
1898+
on f uncons s t
1899+
where
1900+
f :: Maybe (Char, Text) -> Maybe (Char, Text) -> Bool
1901+
f Nothing _ = True
1902+
f _ Nothing = False
1903+
f (Just (sc,ss)) (Just (tc,ts)) =
1904+
subseqOf ts $
1905+
if sc == tc
1906+
then s
1907+
else ss
19141908

19151909
-------------------------------------------------------------------------------
19161910
-- * View patterns

0 commit comments

Comments
 (0)