Skip to content

Commit 173c1ae

Browse files
committed
WIP: Text: isSubsequenceOf: ({null, unsafeHead, unsafeTail} -> uncons)
As suggested, indeed `uncons` replaces 3 funciton invocations with 1.
1 parent c53b59f commit 173c1ae

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/Data/Text.hs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ 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)
257259

258260
-- $setup
259261
-- >>> import Data.Text
@@ -1892,11 +1894,23 @@ isSubsequenceOf tf sf
18921894
| length sf > length tf = False
18931895
| otherwise = subseqOf tf sf
18941896
where
1895-
subseqOf t s
1896-
| null s = True
1897-
| null t = False
1898-
| unsafeHead s == unsafeHead t = subseqOf (unsafeTail t) (unsafeTail s)
1899-
| otherwise = subseqOf (unsafeTail t) s
1897+
subseqOf :: Text -> Text -> Bool
1898+
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)
19001914

19011915
-------------------------------------------------------------------------------
19021916
-- * View patterns

0 commit comments

Comments
 (0)