You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It'd be nice to be able to quickly produce a list of generated environment variable names being used, when one makes an instance of FromEnv for a type that has a Generics instance. That way, the list can be included in documentation.
The following code provides a method extract to do this:
classExtractawhereextract::a-> [String]
default extract :: (GExtract (Repa), Generica) =>a-> [String]
extract x = gExtract (from x) defOption
classGExtractfwheregExtract::fa->Option-> [String]
instance (GExtracta, GExtractb) =>GExtract (a:*:b) where
gExtract (a :*: b) opts = gExtract a opts <> gExtract b opts
instanceGExtracta=>GExtract (C1ia) where
gExtract (M1 x) = gExtract x
instanceGExtracta=>GExtract (D1ia) where
gExtract (M1 x) = gExtract x
instance (Selectors, Vara) =>GExtract (S1s (K1ia)) where
gExtract m@(M1 (K1 def)) opts = [toEnvName opts $ selName m]
where `selName` and `snake` are split out into top level functions to avoid duplication (expand for details).
toEnvName::Option->String->String
toEnvName Option{..} xs =let name = snake (drop dropPrefixCount xs)
inif customPrefix ==memptythen name
elsemap toUpper customPrefix ++"_"++ name
snake::String->String
snake =map toUpper . snakeCase
whereapplyFirst:: (Char->Char) ->String->String
applyFirst _ []=[]
applyFirst f [x] = [f x]
applyFirst f (x:xs) = f x: xs
snakeCase::String->String
snakeCase = u . applyFirst toLower
where u []=[]
u (x:xs) | isUpper x ='_': toLower x : snakeCase xs
|otherwise= x : u xs
Is this a feature that could be added to Envy?
The text was updated successfully, but these errors were encountered:
It'd be nice to be able to quickly produce a list of generated environment variable names being used, when one makes an instance of
FromEnv
for a type that has aGenerics
instance. That way, the list can be included in documentation.The following code provides a method
extract
to do this:where `selName` and `snake` are split out into top level functions to avoid duplication (expand for details).
Is this a feature that could be added to Envy?
The text was updated successfully, but these errors were encountered: