graphql-engine/server/src-lib/Data/Sequence/NonEmpty.hs

34 lines
604 B
Haskell
Raw Normal View History

module Data.Sequence.NonEmpty
2018-06-27 16:11:32 +03:00
( NESeq
, (<|)
, (|>)
, init
, head
, toSeq
) where
import qualified Data.Sequence as Seq
import Prelude (Eq, Show, fst, (.))
2018-06-27 16:11:32 +03:00
infixr 5 <|
infixl 5 |>
newtype NESeq a
= NESeq { unNESeq :: (a, Seq.Seq a)}
deriving (Show, Eq)
init :: a -> NESeq a
init a = NESeq (a, Seq.empty)
head :: NESeq a -> a
head = fst . unNESeq
(|>) :: NESeq a -> a -> NESeq a
(NESeq (h, l)) |> v = NESeq (h, l Seq.|> v)
(<|) :: a -> NESeq a -> NESeq a
v <| (NESeq (h, l)) = NESeq (v, h Seq.<| l)
toSeq :: NESeq a -> Seq.Seq a
toSeq (NESeq (v, l)) = v Seq.<| l