module Data.Greskell.NonEmptyLike
( NonEmptyLike(..)
) where
import qualified Data.Foldable as F
import Data.List.NonEmpty (NonEmpty(..))
import Data.Semigroup (Semigroup, (<>))
import qualified Data.Semigroup as S
class F.Foldable t => NonEmptyLike t where
singleton :: a -> t a
append :: t a -> t a -> t a
toNonEmpty :: t a -> NonEmpty a
instance NonEmptyLike NonEmpty where
singleton a = a :| []
append = (<>)
toNonEmpty = id
instance NonEmptyLike S.First where
singleton = S.First
append = (<>)
toNonEmpty (S.First a) = singleton a
instance NonEmptyLike S.Last where
singleton = S.Last
append = (<>)
toNonEmpty (S.Last a) = singleton a