Skip to content

Commit

Permalink
feat(System.Environment): implement module allowing to read environme…
Browse files Browse the repository at this point in the history
…nt variables
  • Loading branch information
maciejsmolinski committed Aug 15, 2019
1 parent e552c34 commit 3071272
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/System/Environment.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module System.Environment (readEnvString, readEnvInt) where

import Control.Applicative (pure)
import Control.Monad (bind, (>>=))
import Data.Function (identity, ($))
import Data.Maybe (Maybe(..), maybe)
import Effect (Effect)
import Node.Process (lookupEnv)
import Simple.JSON (readJSON_)

readEnvString :: String -> String -> Effect String
readEnvString variable defaultValue = do
maybeValue <- lookupEnv variable
pure $ maybe defaultValue identity maybeValue

readEnvInt :: String -> Int -> Effect Int
readEnvInt variable defaultValue = do
maybeValue <- lookupEnv variable
case (maybeValue >>= readJSON_ :: Maybe Int) of
Nothing -> pure defaultValue
(Just value) -> pure value

0 comments on commit 3071272

Please sign in to comment.