Generate a case expression!
Here's an example for extracting a Maybe Int
Elm.Case.maybe myMaybe
{ nothing = Elm.int 0
, just =
( "value"
, \content ->
Elm.plus (Elm.int 5) content
)
}Generates
case myMaybe of
Nothing ->
0
Just value ->
value + 5Elm.Case.result myResult
{ ok =
Tuple.pair "ok" <|
\ok ->
Elm.string "No errors"
, err =
Tuple.pair "err" <|
\err ->
err
}Generates
case myResult of
Ok ok ->
"No errors"
Err err ->
errElm.Case.custom maybeString
(Elm.Annotation.maybe Elm.Annotation.string)
[ Elm.Case.branch (Elm.Arg.customType "Nothing" ())
(\_ ->
Elm.string "It's nothing, I swear!"
)
, Elm.Case.branch
(Elm.Arg.customType "Just" identity
|> Arg.item (Arg.var "val")
)
(\val ->
Elm.append (Elm.string "Actually, it's: ") val
)
]Generates
case maybeString of
Nothing ->
"It's nothing, I swear!"
Just just ->
"Actually, it's: " ++ just