{-# LANGUAGE DefaultSignatures #-}
module Data.Multimap.Collection (
Collection(..)
) where
import Prelude hiding (filter)
import qualified Prelude as Prelude
import Data.Foldable (foldl', foldr)
import Data.Sequence (Seq)
import qualified Data.Sequence as Seq
import Data.Set (Set)
import qualified Data.Set as Set
class Foldable c => Collection c where
singleton :: v -> c v
default singleton :: Applicative c => v -> c v
singleton = pure
filter :: (v -> Bool) -> c v -> c v
size :: c v -> Int
size = foldl' (\n _ -> n + 1) 0
null :: c v -> Bool
null = foldr (\_ _ -> False) True
instance Collection [] where
filter = Prelude.filter
instance Collection Seq where
size = Seq.length
filter = Seq.filter
null = Seq.null
instance Collection Set where
singleton = Set.singleton
filter = Set.filter
size = Set.size
null = Set.null