Popularity
1.7
Growing
Activity
0.0
Stable
0
3
0

Monthly Downloads: 15
Programming language: Haskell
License: MIT License
Tags: Development    

generic-env alternatives and similar packages

Based on the "Development" category.
Alternatively, view generic-env alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of generic-env or a related project?

Add another 'Development' Package

README

generic-env

generic-env lets you produce your generic type from a given subset of environment variables.

Usage

{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeApplications #-}

module Example1 where

import GenericEnv
import GHC.Generics
import System.Environment

data AppEnv = AppEnv { name :: String, ver :: String } deriving (Generic, Show)

main :: IO ()
main = do
  setEnv "APP_NAME" "wow"
  setEnv "APP_VER" "1.0"
  print =<< fromEnv @AppEnv (withPrefix "APP_")
> main
Right (AppEnv {name = "wow", ver = "1.0"})

Let's change our version from String to Float:

data AppEnv = AppEnv { name :: String, ver :: Float } deriving (Generic, Show)

and run the same code:

> main
Right (AppEnv {name = "wow", ver = 1.0})

Next, try making the version an integer:

data AppEnv = AppEnv { name :: String, ver :: Int } deriving (Generic, Show)
> main
Left "Could not parse value of type 'Int' for the field named 'ver' from environment variable 'APP_VER=1.0'"

Idea

This project is based on an idea posted here: https://github.com/patrickt/haskell-project-ideas.

You can check it out for other project ideas.

Documentation

For complete docs, visit https://hackage.haskell.org/package/generic-env.

LICENSE

MIT License


*Note that all licence references and agreements mentioned in the generic-env README section above are relevant to that project's source code only.