Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Functions for conditionally running IO
actions based on an environment
variable.
Since: 0.1
Synopsis
- guardSet :: String -> IO a -> IO (Maybe a)
- guardSet_ :: String -> IO a -> IO ()
- guardExpected :: String -> String -> IO a -> IO (Maybe a)
- guardExpected_ :: String -> String -> IO a -> IO ()
- guardPredicate :: String -> (String -> Bool) -> IO a -> IO (Maybe a)
- guardPredicate_ :: String -> (String -> Bool) -> IO a -> IO ()
Checking environment variable is set
guardSet :: String -> IO a -> IO (Maybe a) Source #
runs guardSet
var ioio
iff
- The environment variable
var
is set.
guardSet
var ===guardPredicate
var (const
True
)
Examples
>>>
guardSet "NOT_SET" (putStrLn "ran io" $> True)
Nothing
>>>
setEnv "SET" "foo"
>>>
guardSet "SET" (putStrLn "ran io" $> True)
ran io Just True
Since: 0.1
guardSet_ :: String -> IO a -> IO () Source #
Variant of guardSet
that ignores the return value.
Since: 0.1
Checking environment variable match
guardExpected :: String -> String -> IO a -> IO (Maybe a) Source #
runs guardExpected
var expected ioio
iff
- The environment variable
var
is set. var
's value equalsexpected
. This is case-insensitive.
guardExpected
var expected ===guardPredicate
var (\a b ->fmap
toLower
a ==fmap
toLower
b)
Examples
>>>
guardExpected "NOT_SET" "val" (putStrLn "ran io" $> True)
Nothing
>>>
setEnv "WRONG_VAL" "good_val"
>>>
guardExpected "WRONG_VAL" "bad_val" (putStrLn "ran io" $> True)
Nothing
>>>
setEnv "WILL_RUN" "val"
>>>
guardExpected "WILL_RUN" "VAL" (putStrLn "ran io" $> True)
ran io Just True
Since: 0.1
guardExpected_ :: String -> String -> IO a -> IO () Source #
Variant of guardExpected_
that ignores the return value.
Since: 0.1
Checking environment variable predicate
guardPredicate :: String -> (String -> Bool) -> IO a -> IO (Maybe a) Source #
This is the most general way to check an environment variable.
runs guardPredicate
var p ioio
iff
- The environment variable
var
is set. var
's value satisfies predicatep
.
Examples
>>>
guardPredicate "NOT_SET" (const True) (putStrLn "ran io" $> True)
Nothing
>>>
setEnv "CASE_WRONG" "VAL"
>>>
guardPredicate "CASE_WRONG" (== "val") (putStrLn "ran io" $> True)
Nothing
>>>
setEnv "WILL_RUN" "VAL"
>>>
guardPredicate "WILL_RUN" (== "VAL") (putStrLn "ran io" $> True)
ran io Just True
Since: 0.1
guardPredicate_ :: String -> (String -> Bool) -> IO a -> IO () Source #
Variant of guardPredicate
that ignores the return value.
Since: 0.1