module Data.SeqHelper (
sequenceHead
, sequenceTail
, removeNextDuplicate
) where
import qualified Data.Sequence as Sequence
sequenceHead :: Sequence.Seq a -> Sequence.Seq a
sequenceHead :: Seq a -> Seq a
sequenceHead (Seq a
headS Sequence.:|> a
_) = Seq a
headS
sequenceHead Seq a
_ = Seq a
forall a. Seq a
Sequence.empty
{-# INLINE sequenceHead #-}
sequenceTail :: Sequence.Seq a -> Sequence.Seq a
sequenceTail :: Seq a -> Seq a
sequenceTail (a
_ Sequence.:<| Seq a
tailS) = Seq a
tailS
sequenceTail Seq a
_ = Seq a
forall a. Seq a
Sequence.empty
{-# INLINE sequenceTail #-}
removeNextDuplicate :: Eq a => Sequence.Seq a -> Sequence.Seq a
removeNextDuplicate :: Seq a -> Seq a
removeNextDuplicate Seq a
Sequence.Empty = Seq a
forall a. Seq a
Sequence.empty
removeNextDuplicate xs :: Seq a
xs@(a
_ Sequence.:<| Seq a
Sequence.Empty) = Seq a
xs
removeNextDuplicate (a
x Sequence.:<| tailXs :: Seq a
tailXs@(a
y Sequence.:<| Seq a
_))
| a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
/= a
y = a
x a -> Seq a -> Seq a
forall a. a -> Seq a -> Seq a
Sequence.<| Seq a -> Seq a
forall a. Eq a => Seq a -> Seq a
removeNextDuplicate Seq a
tailXs
| Bool
otherwise = Seq a -> Seq a
forall a. Eq a => Seq a -> Seq a
removeNextDuplicate Seq a
tailXs