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
  {- INLINE uncons #-}
  uncons :: a -> Maybe (Char,a)

instance Uncons ([] Char) where
  {- INLINE uncons #-}
  uncons :: [Char] -> Maybe (Char, [Char])
uncons [] = forall a. Maybe a
Nothing
  uncons (Char
x:[Char]
xs) = forall a. a -> Maybe a
Just (Char
x,[Char]
xs)

instance Uncons (Seq Char) where
  {- INLINE uncons #-}
  uncons :: Seq Char -> Maybe (Char, Seq Char)
uncons Seq Char
s = case forall a. Seq a -> ViewL a
viewl Seq Char
s of
               ViewL Char
EmptyL -> forall a. Maybe a
Nothing
               Char
x :< Seq Char
xs -> forall a. a -> Maybe a
Just (Char
x,Seq Char
xs)

instance Uncons SBS.ByteString where
  {- INLINE uncons #-}
  uncons :: ByteString -> Maybe (Char, ByteString)
uncons = ByteString -> Maybe (Char, ByteString)
SBS.uncons

instance Uncons LBS.ByteString where
  {- INLINE uncons #-}
  uncons :: ByteString -> Maybe (Char, ByteString)
uncons = ByteString -> Maybe (Char, ByteString)
LBS.uncons

-- | @since 1.3.1
instance Uncons T.Text where
  {- INLINE uncons #-}
  uncons :: Text -> Maybe (Char, Text)
uncons = Text -> Maybe (Char, Text)
T.uncons

-- | @since 1.3.1
instance Uncons TL.Text where
  {- INLINE uncons #-}
  uncons :: Text -> Maybe (Char, Text)
uncons = Text -> Maybe (Char, Text)
TL.uncons