{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Internal.SnocList
( SnocList
, fromList
, empty
, snoc
, singleton
) where
import Data.Foldable
import Data.Hashable (Hashable)
newtype SnocList a = SnocList [a]
deriving(SnocList a -> SnocList a -> Bool
(SnocList a -> SnocList a -> Bool)
-> (SnocList a -> SnocList a -> Bool) -> Eq (SnocList a)
forall a. Eq a => SnocList a -> SnocList a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SnocList a -> SnocList a -> Bool
$c/= :: forall a. Eq a => SnocList a -> SnocList a -> Bool
== :: SnocList a -> SnocList a -> Bool
$c== :: forall a. Eq a => SnocList a -> SnocList a -> Bool
Eq, Int -> SnocList a -> Int
SnocList a -> Int
(Int -> SnocList a -> Int)
-> (SnocList a -> Int) -> Hashable (SnocList a)
forall a. Hashable a => Int -> SnocList a -> Int
forall a. Hashable a => SnocList a -> Int
forall a. (Int -> a -> Int) -> (a -> Int) -> Hashable a
hash :: SnocList a -> Int
$chash :: forall a. Hashable a => SnocList a -> Int
hashWithSalt :: Int -> SnocList a -> Int
$chashWithSalt :: forall a. Hashable a => Int -> SnocList a -> Int
Hashable)
fromList :: [a] -> SnocList a
fromList :: [a] -> SnocList a
fromList = [a] -> SnocList a
forall a. [a] -> SnocList a
SnocList ([a] -> SnocList a) -> ([a] -> [a]) -> [a] -> SnocList a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> [a]
forall a. [a] -> [a]
reverse
singleton :: a -> SnocList a
singleton :: a -> SnocList a
singleton a
x = [a] -> SnocList a
forall a. [a] -> SnocList a
SnocList [a
x]
empty :: SnocList a
empty :: SnocList a
empty = [a] -> SnocList a
forall a. [a] -> SnocList a
SnocList []
snoc :: SnocList a -> a -> SnocList a
snoc :: SnocList a -> a -> SnocList a
snoc (SnocList [a]
xs) a
x = [a] -> SnocList a
forall a. [a] -> SnocList a
SnocList (a
xa -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
xs)
instance Foldable SnocList where
foldMap :: (a -> m) -> SnocList a -> m
foldMap a -> m
f = (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap a -> m
f ([a] -> m) -> (SnocList a -> [a]) -> SnocList a -> m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SnocList a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList
toList :: SnocList a -> [a]
toList (SnocList [a]
xs) = [a] -> [a]
forall a. [a] -> [a]
reverse [a]
xs
instance Semigroup (SnocList a) where
(SnocList [a]
l) <> :: SnocList a -> SnocList a -> SnocList a
<> (SnocList [a]
r) = [a] -> SnocList a
forall a. [a] -> SnocList a
SnocList ([a]
r [a] -> [a] -> [a]
forall a. Semigroup a => a -> a -> a
<> [a]
l)
instance Monoid (SnocList a) where
mempty :: SnocList a
mempty = SnocList a
forall a. SnocList a
empty