module Data.Multimap.Seq (
SeqMultimap,
popFirst, popLast
) where
import Data.Functor.Compose (Compose(..))
import Data.Sequence (Seq)
import qualified Data.Sequence as Seq
import Data.Multimap.Generic (Multimap, modifyManyF)
type SeqMultimap = Multimap Seq
popFirst :: Ord k => k -> SeqMultimap k v -> Maybe (v, SeqMultimap k v)
popFirst k = getCompose . modifyManyF (Compose . go . Seq.viewl) k where
go Seq.EmptyL = Nothing
go (v Seq.:< c) = Just (v, c)
popLast :: Ord k => k -> SeqMultimap k v -> Maybe (v, SeqMultimap k v)
popLast k = getCompose . modifyManyF (Compose . go . Seq.viewr) k where
go Seq.EmptyR = Nothing
go (c Seq.:> v) = Just (v, c)