graphql-engine/server/src-lib/Hasura/GraphQL/NonEmptySeq.hs

36 lines
642 B
Haskell
Raw Normal View History

2018-06-27 16:11:32 +03:00
{-# LANGUAGE NoImplicitPrelude #-}
module Hasura.GraphQL.NonEmptySeq
( NESeq
, (<|)
, (|>)
, init
, head
, toSeq
) where
import qualified Data.Sequence as Seq
import Hasura.Prelude hiding (head)
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