stripPrefix package:rio

O(n) The stripPrefix function takes two ByteStrings and returns Just the remainder of the second iff the first is its prefix, and otherwise Nothing.
The stripPrefix function drops the given prefix from a list. It returns Nothing if the list did not start with the prefix given, or Just the list after the prefix, if it does.
>>> stripPrefix "foo" "foobar"
Just "bar"
>>> stripPrefix "foo" "foo"
Just ""
>>> stripPrefix "foo" "barfoo"
Nothing
>>> stripPrefix "foo" "barfoobaz"
Nothing
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