read-env-var-0.1.0.0: Functions for safely reading environment variables.

Copyright(c) Dennis Gosnell, 2016
LicenseBSD-style (see LICENSE file)
Maintainercdep.illabout@gmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellSafe
LanguageHaskell2010

System.ReadEnvVar

Description

This Haskell module exports functions for safely reading environment variables.

Synopsis

Documentation

readEnvVar Source

Arguments

:: Read a 
=> String

environment variable to lookup

-> IO (Maybe a) 

Lookup a value from an environment variable and read it in with readMaybe.

>>> import System.Environment (setEnv)
>>> setEnv "TEST_ENV_VAR" "2000"
>>> readEnvVar "TEST_ENV_VAR" :: IO (Maybe Int)
Just 2000
>>> readEnvVar "THIS_ENV_VAR_WILL_NOT_EXIST" :: IO (Maybe Int)
Nothing

readEnvVarDef Source

Arguments

:: Read a 
=> String

environment variable to lookup

-> a

default value to use if the environment variable either does not exist, or cannot be read

-> IO a 

Lookup a value from an environment variable and read it in with readMaybe. If the environment variable doesn't exist, or it can't be read, use the default value.

>>> import System.Environment (setEnv)
>>> setEnv "TEST_ENV_VAR" "1000"
>>> readEnvVarDef "TEST_ENV_VAR" 5 :: IO Int
1000
>>> readEnvVarDef "THIS_ENV_VAR_WILL_NOT_EXIST" 5 :: IO Int
5