TotalMap-0.1.0.0: A total map datatype

Copyright(c) Ed Wastell 2018
LicenseMTL
Maintaineredward@wastell.com
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

TotalMap

Description

A total map from an enum type. Consult the README for more information

Synopsis

Documentation

data TotalMap (tag :: *) (a :: *) Source #

A TotalMap is a total mapping from some enum type tag to some value a: it is isomorphic to `tag -> a`. It uses a generics-sop NP array to store all values, ensuring that every value of tag must have a corresponding value.

Instances
IsEnumType tag => FunctorWithIndex tag (TotalMap tag) Source # 
Instance details

Defined in TotalMap

Methods

imap :: (tag -> a -> b) -> TotalMap tag a -> TotalMap tag b #

imapped :: IndexedSetter tag (TotalMap tag a) (TotalMap tag b) a b #

IsEnumType tag => FoldableWithIndex tag (TotalMap tag) Source # 
Instance details

Defined in TotalMap

Methods

ifoldMap :: Monoid m => (tag -> a -> m) -> TotalMap tag a -> m #

ifolded :: IndexedFold tag (TotalMap tag a) a #

ifoldr :: (tag -> a -> b -> b) -> b -> TotalMap tag a -> b #

ifoldl :: (tag -> b -> a -> b) -> b -> TotalMap tag a -> b #

ifoldr' :: (tag -> a -> b -> b) -> b -> TotalMap tag a -> b #

ifoldl' :: (tag -> b -> a -> b) -> b -> TotalMap tag a -> b #

IsEnumType tag => TraversableWithIndex tag (TotalMap tag) Source # 
Instance details

Defined in TotalMap

Methods

itraverse :: Applicative f => (tag -> a -> f b) -> TotalMap tag a -> f (TotalMap tag b) #

itraversed :: IndexedTraversal tag (TotalMap tag a) (TotalMap tag b) a b #

IsEnumType tag => Monad (TotalMap tag) Source # 
Instance details

Defined in TotalMap

Methods

(>>=) :: TotalMap tag a -> (a -> TotalMap tag b) -> TotalMap tag b #

(>>) :: TotalMap tag a -> TotalMap tag b -> TotalMap tag b #

return :: a -> TotalMap tag a #

fail :: String -> TotalMap tag a #

Functor (TotalMap tag) Source # 
Instance details

Defined in TotalMap

Methods

fmap :: (a -> b) -> TotalMap tag a -> TotalMap tag b #

(<$) :: a -> TotalMap tag b -> TotalMap tag a #

IsEnumType tag => Applicative (TotalMap tag) Source # 
Instance details

Defined in TotalMap

Methods

pure :: a -> TotalMap tag a #

(<*>) :: TotalMap tag (a -> b) -> TotalMap tag a -> TotalMap tag b #

liftA2 :: (a -> b -> c) -> TotalMap tag a -> TotalMap tag b -> TotalMap tag c #

(*>) :: TotalMap tag a -> TotalMap tag b -> TotalMap tag b #

(<*) :: TotalMap tag a -> TotalMap tag b -> TotalMap tag a #

Foldable (TotalMap tag) Source # 
Instance details

Defined in TotalMap

Methods

fold :: Monoid m => TotalMap tag m -> m #

foldMap :: Monoid m => (a -> m) -> TotalMap tag a -> m #

foldr :: (a -> b -> b) -> b -> TotalMap tag a -> b #

foldr' :: (a -> b -> b) -> b -> TotalMap tag a -> b #

foldl :: (b -> a -> b) -> b -> TotalMap tag a -> b #

foldl' :: (b -> a -> b) -> b -> TotalMap tag a -> b #

foldr1 :: (a -> a -> a) -> TotalMap tag a -> a #

foldl1 :: (a -> a -> a) -> TotalMap tag a -> a #

toList :: TotalMap tag a -> [a] #

null :: TotalMap tag a -> Bool #

length :: TotalMap tag a -> Int #

elem :: Eq a => a -> TotalMap tag a -> Bool #

maximum :: Ord a => TotalMap tag a -> a #

minimum :: Ord a => TotalMap tag a -> a #

sum :: Num a => TotalMap tag a -> a #

product :: Num a => TotalMap tag a -> a #

Traversable (TotalMap tag) Source # 
Instance details

Defined in TotalMap

Methods

traverse :: Applicative f => (a -> f b) -> TotalMap tag a -> f (TotalMap tag b) #

sequenceA :: Applicative f => TotalMap tag (f a) -> f (TotalMap tag a) #

mapM :: Monad m => (a -> m b) -> TotalMap tag a -> m (TotalMap tag b) #

sequence :: Monad m => TotalMap tag (m a) -> m (TotalMap tag a) #

IsEnumType tag => Distributive (TotalMap tag) Source # 
Instance details

Defined in TotalMap

Methods

distribute :: Functor f => f (TotalMap tag a) -> TotalMap tag (f a) #

collect :: Functor f => (a -> TotalMap tag b) -> f a -> TotalMap tag (f b) #

distributeM :: Monad m => m (TotalMap tag a) -> TotalMap tag (m a) #

collectM :: Monad m => (a -> TotalMap tag b) -> m a -> TotalMap tag (m b) #

IsEnumType tag => Representable (TotalMap tag) Source # 
Instance details

Defined in TotalMap

Associated Types

type Rep (TotalMap tag) :: Type #

Methods

tabulate :: (Rep (TotalMap tag) -> a) -> TotalMap tag a #

index :: TotalMap tag a -> Rep (TotalMap tag) -> a #

IsEnumType tag => Eq1 (TotalMap tag) Source # 
Instance details

Defined in TotalMap

Methods

liftEq :: (a -> b -> Bool) -> TotalMap tag a -> TotalMap tag b -> Bool #

(IsEnumType tag, Show tag) => Show1 (TotalMap tag) Source # 
Instance details

Defined in TotalMap

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> TotalMap tag a -> ShowS #

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [TotalMap tag a] -> ShowS #

(IsEnumType tag, Eq a) => Eq (TotalMap tag a) Source # 
Instance details

Defined in TotalMap

Methods

(==) :: TotalMap tag a -> TotalMap tag a -> Bool #

(/=) :: TotalMap tag a -> TotalMap tag a -> Bool #

(IsEnumType tag, Show a, Show tag) => Show (TotalMap tag a) Source # 
Instance details

Defined in TotalMap

Methods

showsPrec :: Int -> TotalMap tag a -> ShowS #

show :: TotalMap tag a -> String #

showList :: [TotalMap tag a] -> ShowS #

type Rep (TotalMap tag) Source # 
Instance details

Defined in TotalMap

type Rep (TotalMap tag) = tag

generateAllConstructors :: IsEnumType tag => NP (K tag) (Code tag) Source #

Generate all constructors for some enum type.

TODO: This uses undefined internally as I can not convince the type checker that every constructor has no arguments. This shouldn't be an issue, but feels unsafe so probably should be changed

allTags :: IsEnumType tag => TotalMap tag tag Source #

A TotalMap where each value is its own key. This is the equivalent of id.

getTotalMap :: TotalMap tag a -> tag -> a Source #

Extract a value out of a TotalMap

setTotalMap :: forall tag a. IsEnumType tag => TotalMap tag a -> tag -> a -> TotalMap tag a Source #

Replace a value inside a TotalMap

ixTotal :: IsEnumType tag => tag -> Lens' (TotalMap tag a) a Source #

A Lens into a value of a TotalMap

type IsEnumType a = (Generic a, All ([Type] ~ ([] :: [Type])) (Code a)) #

Constraint that captures that a datatype is an enumeration type, i.e., none of the constructors have any arguments.

Since: generics-sop-0.3.1.0