File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -167,6 +167,7 @@ module Data.Text
167167 , isPrefixOf
168168 , isSuffixOf
169169 , isInfixOf
170+ , isSubsequenceOf
170171
171172 -- ** View patterns
172173 , stripPrefix
@@ -1877,6 +1878,22 @@ isInfixOf needle haystack
18771878 | otherwise = not . L. null . indices needle $ haystack
18781879{-# INLINE [1] isInfixOf #-}
18791880
1881+ -- | The 'isSubsequenceOf' function takes two 'Text's and returns
1882+ -- 'True' iff the first is a subsequence of a second.
1883+ -- (characters of the first argument appear in same sequential order in
1884+ -- the second, to say if first argument that can be derived by deleting some
1885+ -- or no elements from the second).
1886+ isSubsequenceOf :: Text -> Text -> Bool
1887+ isSubsequenceOf sf tf
1888+ | length sf > length tf = False
1889+ | otherwise = subseqOf sf tf
1890+ where
1891+ subseqOf s t
1892+ | null s = True
1893+ | null t = False
1894+ | unsafeHead s == unsafeHead t = subseqOf (unsafeTail s) (unsafeTail t)
1895+ | otherwise = subseqOf s $ unsafeTail t
1896+
18801897-------------------------------------------------------------------------------
18811898-- * View patterns
18821899
You can’t perform that action at this time.
0 commit comments