module Text.Regex.TDFA.NewDFA.Uncons(Uncons(uncons)) where
import qualified Data.ByteString.Char8 as SBS(ByteString,uncons)
import qualified Data.ByteString.Lazy.Char8 as LBS(ByteString,uncons)
import Data.Sequence(Seq,viewl,ViewL(EmptyL,(:<)))
import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
class Uncons a where
uncons :: a -> Maybe (Char,a)
instance Uncons ([] Char) where
uncons :: [Char] -> Maybe (Char, [Char])
uncons [] = Maybe (Char, [Char])
forall a. Maybe a
Nothing
uncons (x :: Char
x:xs :: [Char]
xs) = (Char, [Char]) -> Maybe (Char, [Char])
forall a. a -> Maybe a
Just (Char
x,[Char]
xs)
instance Uncons (Seq Char) where
uncons :: Seq Char -> Maybe (Char, Seq Char)
uncons s :: Seq Char
s = case Seq Char -> ViewL Char
forall a. Seq a -> ViewL a
viewl Seq Char
s of
EmptyL -> Maybe (Char, Seq Char)
forall a. Maybe a
Nothing
x :: Char
x :< xs :: Seq Char
xs -> (Char, Seq Char) -> Maybe (Char, Seq Char)
forall a. a -> Maybe a
Just (Char
x,Seq Char
xs)
instance Uncons SBS.ByteString where
uncons :: ByteString -> Maybe (Char, ByteString)
uncons = ByteString -> Maybe (Char, ByteString)
SBS.uncons
instance Uncons LBS.ByteString where
uncons :: ByteString -> Maybe (Char, ByteString)
uncons = ByteString -> Maybe (Char, ByteString)
LBS.uncons
instance Uncons T.Text where
uncons :: Text -> Maybe (Char, Text)
uncons = Text -> Maybe (Char, Text)
T.uncons
instance Uncons TL.Text where
uncons :: Text -> Maybe (Char, Text)
uncons = Text -> Maybe (Char, Text)
TL.uncons