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 [] = Maybe (Char, [Char])
forall a. Maybe a
Nothing
  uncons (Char
x:[Char]
xs) = (Char, [Char]) -> Maybe (Char, [Char])
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 Seq Char -> ViewL Char
forall a. Seq a -> ViewL a
viewl Seq Char
s of
               ViewL Char
EmptyL -> Maybe (Char, Seq Char)
forall a. Maybe a
Nothing
               Char
x :< 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
  {- 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