Extra functions for working with Cmds.
Similar to perform but takes Result msg and performs action only on Ok.
attempted : Cmd String
attempted =
attempt <| Ok "I'm fine"
attempt (Err "Failed") == Cmd.none
--> TrueSimilar to attempt but works with Maybe instead
maybeCmd : Cmd String
maybeCmd =
maybe <| Just 1
maybe Nothing == Cmd.none
--> TrueConstruct from Result.
resultCmd : Cmd String
resultCmd =
fromResult toString (Ok 1)
fromResult toString (Err ())
--> Cmd.noneConstruct from Maybe.
stringCmd : Cmd String
stringCmd =
toString (Just 1)
fromMaybe toString Nothing
--> Cmd.noneCreates pair model with Cmd.none
pair : ( String, Cmd msg )
pair = pure "foo"
pair
|> Tuple.second
|> ((==) Cmd.none)
--> TrueAdd Cmd to model to create a pair.
Add new cmd to an existing pair.
Trigger Cmd from Msg and create a pair
Add new trigger of Msg to an existing pair.
Cmd costructor. Usefull when you want to artificially emit Cmd from update function.
"real world" example: