module Data.NonEmptyList
( -- * Types
NonEmptyList
-- * Conversions
, singleton
, toList
, fromList
-- * Manipulation
, head
, push
, tail
) where
import Prelude hiding (head, tail)
data NonEmptyList a = NonEmptyList a [a] deriving (Show, Eq, Ord)
singleton :: a -> NonEmptyList a
singleton x = NonEmptyList x []
toList :: NonEmptyList a -> [a]
toList (NonEmptyList h t) = h:t
fromList :: [a] -> Maybe (NonEmptyList a)
fromList [] = Nothing
fromList (x:xs) = Just $ NonEmptyList x xs
push :: a -> NonEmptyList a -> NonEmptyList a
push x (NonEmptyList lx ltail) = NonEmptyList x (lx:ltail)
head :: NonEmptyList a -> a
head (NonEmptyList x _) = x
tail :: NonEmptyList a -> [a]
tail (NonEmptyList _ x) = x