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