forked from orion/obsidian
1.0 KiB
1.0 KiB
Extends Alt with an empty value:
class Alt f <= Plus f where
empty :: forall a. f a
[!info] Conceptually, this lives next to Applicative in my mind; in Maybe for example
pure
andempty
are aliases forJust
andNothing
.
In Array, empty
is empty array []
. In Maybe, empty
is Nothing
.
The most common place you'll see empty
is when using MaybeT as an early return:
logDebug :: String -> Effect Unit
logDebug msg = void $ runMaybeT do
env <- MaybeT $ Process.lookupEnv "NODE_ENV"
when (env /= "DEVELOPMENT") empty
lift $ Console.log msg
this is equivalent to:
logDebug :: String -> Effect Unit
logDebug msg = do
menv <- Process.lookupEnv "NODE_ENV"
case menv of
Just env ->
if env == "DEVELOPMENT" then
Console.log msg
else
pure unit
Nothing -> pure unit
[!info] Note that guard is a shorthand available for
when (..) empty