Skip to content

Commit fdd4285

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

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
@@ -253,6 +253,8 @@ 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)
256258

257259
-- $setup
258260
-- >>> import Data.Text
@@ -1888,11 +1890,23 @@ isSubsequenceOf tf sf
18881890
| length sf > length tf = False
18891891
| otherwise = subseqOf tf sf
18901892
where
1891-
subseqOf t s
1892-
| null s = True
1893-
| null t = False
1894-
| unsafeHead s == unsafeHead t = subseqOf (unsafeTail t) (unsafeTail s)
1895-
| otherwise = subseqOf (unsafeTail t) s
1893+
subseqOf :: Text -> Text -> Bool
1894+
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)
18961910

18971911
-------------------------------------------------------------------------------
18981912
-- * View patterns

0 commit comments

Comments
 (0)