-------------------------------------------------------------------
-- |
-- Module       : Data.Geospatial.Internal.SeqHelpers
-- Copyright    : (C) 2014-2019 HS-GeoJSON Project
-- License      : BSD-style (see the file LICENSE.md)
-- Maintainer   : Andrew Newman
-------------------------------------------------------------------
module Data.SeqHelper (
  sequenceHead
  , sequenceTail
  , removeNextDuplicate
  ) where

import qualified Data.Sequence as Sequence

-- All but the last
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 #-}

-- All but the first
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