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 Int
maybeCmd =
maybe <| Just 1
maybe Nothing == Cmd.none
--> TrueConstruct from Result.
resultCmd : Cmd (Result Never Int)
resultCmd =
fromResult identity (Ok 1)
fromResult identity (Err ())
--> Cmd.noneConstruct from Maybe.
maybeCmd : Cmd (Maybe Int)
maybeCmd =
identity (Just 1)
fromMaybe identity 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.
Add new cmd to an existing pair under a certain condition.
prevCmd : Cmd String
prevCmd =
perform "foo"
newCmd : Cmd String
newCmd =
perform "bar"
( "model", prevCmd )
|> addIf False newCmd
|> Tuple.second
|> ((==) prevCmd)
--> True
Cmd costructor. Useful when you want to artificially emit Cmd from update function.
"real world" example: