Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Support for specifying overrides of values based on parameters.
For example, an entity may have a name that you want to override on a
per-language basis. A single value like this may be represented as a
value. Such a value will have a default
name, as well as zero or more overrides, keyed by WithOverrides
Language NameLanguage
.
A MapWithOverrides
type is also provided for ease of overriding values
inside of a map.
Synopsis
- data WithOverrides p v
- plain :: v -> WithOverrides p v
- overridden :: v -> Map p v -> WithOverrides p v
- unoverriddenValue :: WithOverrides p v -> v
- overriddenValues :: WithOverrides p v -> Map p v
- data MapWithOverrides p k v
- plainMap :: Map k v -> MapWithOverrides p k v
- mapWithOverrides :: Map k (WithOverrides p v) -> MapWithOverrides p k v
- addOverrideMap :: (Ord p, Ord k, Show p, Show k) => p -> Map k v -> MapWithOverrides p k v -> MapWithOverrides p k v
- addOverrideMaps :: (Ord p, Ord k, Show p, Show k) => Map p (Map k v) -> MapWithOverrides p k v -> MapWithOverrides p k v
- applyOverrideMaps :: (Ord p, Ord k, Show p, Show k) => Map p (Map k v) -> Map k v -> MapWithOverrides p k v
- insertMapOverride :: (Ord p, Ord k, Show p, Show k) => p -> k -> v -> MapWithOverrides p k v -> MapWithOverrides p k v
- overriddenMapLookup :: (Ord p, Ord k) => p -> k -> MapWithOverrides p k v -> Maybe v
Documentation
data WithOverrides p v Source #
Represents a default value of type v
with optional overrides keyed by
parameter type p
. The type p
must have an Ord
instance.
plain :: v -> WithOverrides p v Source #
Creates a WithOverrides
with the given default value v
, and no
overridden values.
overridden :: v -> Map p v -> WithOverrides p v Source #
Creates a WithOverrides
with the given default value v
, and overridden
values in the map.
unoverriddenValue :: WithOverrides p v -> v Source #
The default, unoverriden value for the WithOverrides
. Lookups on the
override will return this value a given parameter doesn't have an
override.
overriddenValues :: WithOverrides p v -> Map p v Source #
Any overridden values that have been added to the WithOverrides
.
data MapWithOverrides p k v Source #
Represents a map from k
values to v
values, where each entry can be
overridden based on parameter p
. A key is either present with a default
value and possibly some overridden values, or it is completely absent -- it
is not possible for a key to have overridden values but no default value.
plainMap :: Map k v -> MapWithOverrides p k v Source #
Converts a plain map to a MapWithOverrides
without any overrides.
mapWithOverrides :: Map k (WithOverrides p v) -> MapWithOverrides p k v Source #
Direct constructor for MapWithOverrides
.
addOverrideMap :: (Ord p, Ord k, Show p, Show k) => p -> Map k v -> MapWithOverrides p k v -> MapWithOverrides p k v Source #
Adds a collection of overrides v
for multiple keys k
, all under a single
parameter p
, to a MapWithOverrides
.
It is an error for a parameter to override a key that is not present in the defaults map.
addOverrideMaps :: (Ord p, Ord k, Show p, Show k) => Map p (Map k v) -> MapWithOverrides p k v -> MapWithOverrides p k v Source #
Adds overrides v
for multiple keys k
under multiple parameters p
to a
MapWithOverrides
.
It is an error for a parameter to override a key that is not present in the defaults map.
applyOverrideMaps :: (Ord p, Ord k, Show p, Show k) => Map p (Map k v) -> Map k v -> MapWithOverrides p k v Source #
Constructs a MapWithOverrides
from a map of default values and a bunch of
parameter-specific maps overlaid on top of it.
It is an error for a parameter to override a key that is not present in the defaults map.
insertMapOverride :: (Ord p, Ord k, Show p, Show k) => p -> k -> v -> MapWithOverrides p k v -> MapWithOverrides p k v Source #
Adds an override v
for key k
under parameter p
to a
MapWithOverrides
.
It is an error for a parameter to override a key that is not present in the defaults map.
overriddenMapLookup :: (Ord p, Ord k) => p -> k -> MapWithOverrides p k v -> Maybe v Source #
Looks up a value for k
in the given MapWithOverrides
, with the
possibility that the value is overridden by the parameter p
.