envy icon indicating copy to clipboard operation
envy copied to clipboard

What is the proper way of grouping env vars into product Haskell types?

Open coderfromhere opened this issue 2 years ago • 0 comments

Hi! I'd like to know what is the proper way to group multiple independent env vars prefixed with a component name into a Haskell component structure that represent the component as a whole? Basically I want these vars

DB_NAME=
DB_PORT=

to be mapped into a single data DbSettings ..., so that DbSettings itself can be used in larger env var parsers like:

data AppSettings = AppSettings
    { something :: Text
    , dbSettings :: DbSettings
    }

Normally, I'd first define an instance of Var a, but fromVar is only provided with a single variable, not a set of items. Does it mean that I should omit declaring instances for Var a and proceed with manual parsing inside instances of FromEnv a?

coderfromhere avatar Oct 07 '21 14:10 coderfromhere