generic-cache-1.1: Safe generic caching

Safe HaskellNone
LanguageHaskell98

Data.GenericCache

Contents

Synopsis

Cache type

data GenericCache #

A map from a type fingerprint (SomeTypeRep) to a wrapped value (Dynamic) of that type.

Instances
Generic GenericCache # 
Instance details

Defined in Data.GenericCache

Associated Types

type Rep GenericCache :: Type -> Type #

Semigroup GenericCache # 
Instance details

Defined in Data.GenericCache

Monoid GenericCache # 
Instance details

Defined in Data.GenericCache

HasGenericCache GenericCache # 
Instance details

Defined in Data.GenericCache

type Rep GenericCache # 
Instance details

Defined in Data.GenericCache

type Rep GenericCache = D1 (MetaData "GenericCache" "Data.GenericCache" "generic-cache-1.1-inplace" True) (C1 (MetaCons "GenericCache" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Map SomeTypeRep Dynamic))))

class HasGenericCache a where #

How to find the GenericCache value.

Lens functions

anyLens :: forall a s. (HasGenericCache s, Typeable a, HasCallStack) => a -> Lens' s a #

Generic lens, allows access to a single a inside a value s. It has a default value argument.

> view (anyLens 'a') $ (anyLens 'a' %~ succ . succ) (mempty :: GenericCache)
c

maybeLens :: forall a s. (HasGenericCache s, Typeable a) => Lens' s (Maybe a) #

anyLens for a Maybe value, with default value Nothing.

Map lens functions

atLens :: forall k v s. (HasGenericCache s, Typeable k, Ord k, Typeable v, HasCallStack) => k -> Lens' s (Maybe v) #

An At lens to an element of a map.

mapLens :: forall k v s. (HasGenericCache s, Typeable k, Ord k, Typeable v, HasCallStack) => Lens' s (Map k v) #

Access the whole map that atLens provides element access to:

    > view (mapLens @Char @String) $
        atLens 'x' .~ Just "hello" $
          atLens 'y' .~ Just "world" $
            (mempty :: GenericCache)
    fromList [('x',"hello"),('y',"world")]

Tests