stripPrefix package:text

O(n) Return the suffix of the second string if its prefix matches the entire first string. Examples:
>>> stripPrefix "foo" "foobar"
Just "bar"
>>> stripPrefix ""    "baz"
Just "baz"
>>> stripPrefix "foo" "quux"
Nothing
This 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
O(n) Return the suffix of the second string if its prefix matches the entire first string. Examples:
stripPrefix "foo" "foobar" == Just "bar"
stripPrefix ""    "baz"    == Just "baz"
stripPrefix "foo" "quux"   == Nothing
This 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