Copyright | © Jonathan Lorimer 2023 |
---|---|
License | MIT |
Maintainer | jonathanlorimer@pm.me |
Stability | stable |
Safe Haskell | None |
Language | Haskell2010 |
This module contains the generic machinery for generating a tree representation of your configuration, this tree representation is intended to be used with various sources. The tree structure should match the structure of your (potentially) nested record type.
It is important to note that defaults are injected here, and not in the
parser stage. We use a DefaultSource
instance to inject Pure
values at
the leaves that can be used if the source fetcher doesn't return a value for
that key. In the case that there is no default a 'Free Data.Map.empty' is
placed to represent a required value.
Since: 0.0.2.0
Synopsis
- defaultConfigSource :: (DefaultSource a, Generic a, GConfigSource (Rep a)) => ConfigOptions -> KeyTree Text Text
- class GConfigSource (a :: Type -> Type) where
- gConfigSource :: (Text -> Maybe Text) -> ConfigOptions -> KeyTree Text Text
Default Source Generator
defaultConfigSource :: (DefaultSource a, Generic a, GConfigSource (Rep a)) => ConfigOptions -> KeyTree Text Text Source #
This function is used by the deriving via machinery to dispatch to the
generic machinery, the user should never have to invoke it directly. This
takes in a ConfigOptions
which are retrieved from the deriving via
newtypes, and also threads a DefaultSource
instance through so that we can
dispatch to defaults
in the K1
case.
Since: 0.0.2.0
Generic Machinery
class GConfigSource (a :: Type -> Type) where Source #
This class is the generic version of 'ConfigSource. It recurses on the
generic structure of a type, building up KeyTree
representation.
Since: 0.0.2.0
gConfigSource :: (Text -> Maybe Text) -> ConfigOptions -> KeyTree Text Text Source #
Instances
(GConfigSource a, GConfigSource b) => GConfigSource (a :*: b) Source # | This instance handles product types and is pretty important. We need to
check that recursive calls to You may wonder what happens if there is a Free $ M.singleton fieldName (Pure value) since we need to account for the key corresponding to the record field. So
we really should never hit a case were a recursive call to Since: 0.0.2.0 |
Defined in Cfg.Source.Config gConfigSource :: (Text -> Maybe Text) -> ConfigOptions -> KeyTree Text Text Source # | |
GConfigSource (a :+: b) Source # | Sum types should represent base values, so Since: 0.0.2.0 |
Defined in Cfg.Source.Config gConfigSource :: (Text -> Maybe Text) -> ConfigOptions -> KeyTree Text Text Source # | |
ConfigSource a => GConfigSource (K1 R a :: Type -> Type) Source # | This is the "base case", since GHC.Generics don't recurse the generic
represetation multiple levels, Since: 0.0.2.0 |
Defined in Cfg.Source.Config gConfigSource :: (Text -> Maybe Text) -> ConfigOptions -> KeyTree Text Text Source # | |
(Constructor c, GConfigSource f) => GConfigSource (M1 C c f) Source # | This is the data constructor case, if we are dealing with a
Since: 0.0.2.0 |
Defined in Cfg.Source.Config gConfigSource :: (Text -> Maybe Text) -> ConfigOptions -> KeyTree Text Text Source # | |
(Datatype d, GConfigSource f) => GConfigSource (M1 D d f) Source # | This is the type constructor case, if we are dealing with a
Since: 0.0.2.0 |
Defined in Cfg.Source.Config gConfigSource :: (Text -> Maybe Text) -> ConfigOptions -> KeyTree Text Text Source # | |
(Selector s, GConfigSource f) => GConfigSource (M1 S s f) Source # | This instance is important because it does the work of pulling off the
field selector name, and creating a sub-tree under that key by calling
We detect if a default exists by calling Since: 0.0.2.0 |
Defined in Cfg.Source.Config gConfigSource :: (Text -> Maybe Text) -> ConfigOptions -> KeyTree Text Text Source # |