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 (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
  {- INLINE uncons #-}
  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
  {- 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