cauldron-0.6.1.0: Dependency injection library
Safe HaskellNone
LanguageGHC2021

Cauldron.Beans

Description

A map of Dynamic values.

Synopsis

Documentation

data Beans Source #

A map of Dynamic values, indexed by the TypeRep of each Dynamic. Maintains the invariant that the TypeRep of the key matches the TypeRep of the Dynamic.

Instances

Instances details
Monoid Beans Source # 
Instance details

Defined in Cauldron.Beans

Methods

mempty :: Beans #

mappend :: Beans -> Beans -> Beans #

mconcat :: [Beans] -> Beans #

Semigroup Beans Source #

Union of two Beans maps, right-biased: prefers values from the right Beans map when both contain the same TypeRep key. (Note that Map is left-biased.)

Instance details

Defined in Cauldron.Beans

Methods

(<>) :: Beans -> Beans -> Beans #

sconcat :: NonEmpty Beans -> Beans #

stimes :: Integral b => b -> Beans -> Beans #

IsList Beans Source # 
Instance details

Defined in Cauldron.Beans

Associated Types

type Item Beans 
Instance details

Defined in Cauldron.Beans

Show Beans Source # 
Instance details

Defined in Cauldron.Beans

Methods

showsPrec :: Int -> Beans -> ShowS #

show :: Beans -> String #

showList :: [Beans] -> ShowS #

type Item Beans Source # 
Instance details

Defined in Cauldron.Beans

insert :: Typeable bean => bean -> Beans -> Beans Source #

restrictKeys :: Beans -> Set TypeRep -> Beans Source #

Restrict a Beans map to only those TypeReps found in a Set.

keysSet :: Beans -> Set TypeRep Source #

The set of all TypeRep keys of the map.

singleton :: Typeable bean => bean -> Beans Source #

fromDynList :: [Dynamic] -> Beans Source #

>>> :{
let beans = fromDynList [toDyn False, toDyn @Int 5]
 in (taste @Bool beans, taste @Int beans, taste @String beans)
:}
(Just False,Just 5,Nothing)

Looking for values

taste :: Typeable bean => Beans -> Maybe bean Source #

Check if the Beans map contains a value of type bean.

Monoidal stuff

unionBeansMonoidally :: Set SomeMonoidTypeRep -> Beans -> Beans -> Beans Source #

Union of to Beans maps. If both share a TypeRep key and the key is present in the SomeMonoidTypeRep Set, combine the values monoidally. Otherwise, keep the value from the second Beans map.

someMonoidTypeRepMempty :: SomeMonoidTypeRep -> Dynamic Source #

The mempty value corresponding to the inner TypeRep.

Re-exported

toDyn :: Typeable a => a -> Dynamic #

Converts an arbitrary value into an object of type Dynamic.

The type of the object must be an instance of Typeable, which ensures that only monomorphically-typed objects may be converted to Dynamic. To convert a polymorphic object into Dynamic, give it a monomorphic type signature. For example:

   toDyn (id :: Int -> Int)