>>> stripPrefix "foo" "foobar" Just "bar"
>>> stripPrefix "foo" "foo" Just ""
>>> stripPrefix "foo" "barfoo" Nothing
>>> stripPrefix "foo" "barfoobaz" Nothing
>>> stripPrefix "foo" "foobar" Just "bar"
>>> stripPrefix "" "baz" Just "baz"
>>> stripPrefix "foo" "quux" NothingThis is particularly useful with the ViewPatterns extension to GHC, as follows:
{-# LANGUAGE ViewPatterns #-} import Data.Text as T fnordLength :: Text -> Int fnordLength (stripPrefix "fnord" -> Just suf) = T.length suf fnordLength _ = -1
stripPrefix "foo" "foobar" == Just "bar" stripPrefix "" "baz" == Just "baz" stripPrefix "foo" "quux" == NothingThis is particularly useful with the ViewPatterns extension to GHC, as follows:
{-# LANGUAGE ViewPatterns #-} import Data.Text.Lazy as T fnordLength :: Text -> Int fnordLength (stripPrefix "fnord" -> Just suf) = T.length suf fnordLength _ = -1
stripPrefix "/foo/" "/foo/bar/baz.txt" == Just "bar/baz.txt" stripPrefix "/foo/" "/bar/baz.txt" == NothingThis function operates on logical prefixes, rather than by counting characters. The prefix "/foo/bar/baz" is interpreted the path ("/foo/bar/", "baz"), and will be stripped accordingly:
stripPrefix "/foo/bar/baz" "/foo/bar/baz/qux" == Nothing stripPrefix "/foo/bar/baz" "/foo/bar/baz.txt" == Just ".txt"Since: 0.4.1
>>> stripPrefix "foo" "foobar" Just "bar"
>>> stripPrefix "foo" "foo" Just ""
>>> stripPrefix "foo" "barfoo" Nothing
>>> stripPrefix "foo" "barfoobaz" Nothing
> stripPrefix "foo" "foobar" Just "bar" > stripPrefix "abc" "foobar" Nothing
stripPrefix "foo" "foobar" == Just "bar" stripPrefix "" "baz" == Just "baz" stripPrefix "foo" "quux" == NothingThis is particularly useful with the ViewPatterns extension to GHC, as follows:
{-# LANGUAGE ViewPatterns #-} import Data.Text as T fnordLength :: JSString -> Int fnordLength (stripPrefix "fnord" -> Just suf) = T.length suf fnordLength _ = -1