FiniteCategories-0.1.0.0: Finite categories and usual categorical constructions on them.
CopyrightGuillaume Sabbagh 2021
LicenseGPL-3
Maintainerguillaumesabbagh@protonmail.com
Stabilityexperimental
Portabilityportable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Utils.AssociationList

Description

The type for association lists.

It is used when the Ord constraint of Map is too restrictive.

Synopsis

Documentation

type AssociationList a b = [(a, b)] Source #

The type of association lists (a list of couples).

keys :: AssociationList a b -> [a] Source #

Returns the keys of the association list.

values :: AssociationList a b -> [b] Source #

Returns the values of the association list.

(!-) :: Eq a => a -> AssociationList a b -> Maybe b Source #

If the key is in the association list, returns Just the value associated, otherwise Nothing.

Same as lookup in Map.

(!-!) :: Eq a => AssociationList a b -> a -> b Source #

If the key is in the association list, returns the value associated, otherwise throws an error.

Same as (!) in Map.

(!-?) :: Eq a => b -> a -> AssociationList a b -> b Source #

If the key is in the association list, returns the value associated, otherwise returns a default value.

Same as findWithDefault in Map.

(!-.) :: (Eq a, Eq b) => AssociationList b c -> AssociationList a b -> AssociationList a c Source #

Composition of association lists.

mkAssocListIdentity :: [a] -> AssociationList a a Source #

Constructs the identity association list of a list of values.

For example, mkAssocListIdentity [1,2,3] = [(1,1),(2,2),(3,3)]

enumAssocLists :: [a] -> [b] -> [AssociationList a b] Source #

Enumerates all association lists possible between a domain and a codomain.

functToAssocList :: (a -> b) -> [a] -> AssociationList a b Source #

Transforms a function and a domain into an association list.

assocListToFunct :: Eq a => AssociationList a b -> a -> b Source #

Transforms an association list to a function.

inverse :: AssociationList a b -> AssociationList b a Source #

Inverse of an association list

removeKey :: Eq a => AssociationList a b -> a -> AssociationList a b Source #

Remove all couples with a certain key

removeValue :: Eq b => AssociationList a b -> b -> AssociationList a b Source #

Remove all couples with a certain value