Agda-2.5.2: A dependently typed functional programming language and proof assistant

Safe Haskell | Safe
Language | Haskell2010

Agda.Utils.Bag

Contents

- Query
- Construction
- Destruction
- Traversal
- Instances

Description

A simple overlay over Data.Map to manage unordered sets with duplicates.

Synopsis

- newtype Bag a = Bag {
  - bag :: Map a [a]
  }
- null :: Bag a -> Bool
- size :: Bag a -> Int
- (!) :: Ord a => Bag a -> a -> [a]
- member :: Ord a => a -> Bag a -> Bool
- notMember :: Ord a => a -> Bag a -> Bool
- count :: Ord a => a -> Bag a -> Int
- empty :: Bag a
- singleton :: a -> Bag a
- union :: Ord a => Bag a -> Bag a -> Bag a
- unions :: Ord a => [Bag a] -> Bag a
- insert :: Ord a => a -> Bag a -> Bag a
- fromList :: Ord a => [a] -> Bag a
- groups :: Bag a -> [[a]]
- toList :: Bag a -> [a]
- keys :: Bag a -> [a]
- elems :: Bag a -> [a]
- toAscList :: Bag a -> [a]
- map :: Ord b => (a -> b) -> Bag a -> Bag b
- traverse' :: forall a b m. (Applicative m, Ord b) => (a -> m b) -> Bag a -> m (Bag b)

# Documentation

newtype Bag a #

A set with duplicates. Faithfully stores elements which are equal with regard to (==).

Constructors

Bag |
Fields bag :: Map a [a]

Instances

Foldable Bag # |
Methods fold :: Monoid m => Bag m -> m # foldMap :: Monoid m => (a -> m) -> Bag a -> m # foldr :: (a -> b -> b) -> b -> Bag a -> b # foldr' :: (a -> b -> b) -> b -> Bag a -> b # foldl :: (b -> a -> b) -> b -> Bag a -> b # foldl' :: (b -> a -> b) -> b -> Bag a -> b # foldr1 :: (a -> a -> a) -> Bag a -> a # foldl1 :: (a -> a -> a) -> Bag a -> a # toList :: Bag a -> [a] # null :: Bag a -> Bool # length :: Bag a -> Int # elem :: Eq a => a -> Bag a -> Bool # maximum :: Ord a => Bag a -> a # minimum :: Ord a => Bag a -> a # sum :: Num a => Bag a -> a # product :: Num a => Bag a -> a #
Eq a => Eq (Bag a) # |
Methods (==) :: Bag a -> Bag a -> Bool # (/=) :: Bag a -> Bag a -> Bool #
Ord a => Ord (Bag a) # |
Methods compare :: Bag a -> Bag a -> Ordering # (<) :: Bag a -> Bag a -> Bool # (<=) :: Bag a -> Bag a -> Bool # (>) :: Bag a -> Bag a -> Bool # (>=) :: Bag a -> Bag a -> Bool # max :: Bag a -> Bag a -> Bag a # min :: Bag a -> Bag a -> Bag a #
Show a => Show (Bag a) # |
Methods showsPrec :: Int -> Bag a -> ShowS # show :: Bag a -> String # showList :: [Bag a] -> ShowS #
Ord a => Semigroup (Bag a) # |
Methods (<>) :: Bag a -> Bag a -> Bag a # sconcat :: NonEmpty (Bag a) -> Bag a # stimes :: Integral b => b -> Bag a -> Bag a #
Ord a => Monoid (Bag a) # |
Methods mempty :: Bag a # mappend :: Bag a -> Bag a -> Bag a # mconcat :: [Bag a] -> Bag a #
Null (Bag a) # |
Methods empty :: Bag a # null :: Bag a -> Bool #

# Query

null :: Bag a -> Bool #

size :: Bag a -> Int #

(!) :: Ord a => Bag a -> a -> [a] #

`bag ! a` finds all elements equal to `a`.

member :: Ord a => a -> Bag a -> Bool #

notMember :: Ord a => a -> Bag a -> Bool #

count :: Ord a => a -> Bag a -> Int #

Return the multiplicity of the given element.

# Construction

empty :: Bag a #

singleton :: a -> Bag a #

union :: Ord a => Bag a -> Bag a -> Bag a #

unions :: Ord a => [Bag a] -> Bag a #

insert :: Ord a => a -> Bag a -> Bag a #

    insert a b = union b (singleton a)

fromList :: Ord a => [a] -> Bag a #

    fromList = unions . map singleton

# Destruction

groups :: Bag a -> [[a]] #

Returns the elements of the bag, grouped by equality (==).

toList :: Bag a -> [a] #

Returns the bag, with duplicates.

keys :: Bag a -> [a] #

Returns the bag without duplicates.

elems :: Bag a -> [a] #

Returns the bag, with duplicates.

toAscList :: Bag a -> [a] #

# Traversal

map :: Ord b => (a -> b) -> Bag a -> Bag b #

traverse' :: forall a b m. (Applicative m, Ord b) => (a -> m b) -> Bag a -> m (Bag b) #

# Instances