GlobalWebIndex/cmd-extra/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

Cmd.Extra

Extra functions for working with Cmds.

Basics

perform : msg -> Cmd msg

Cmd costructor. Usefull when you want to artificially emit Cmd from update function.

perform "Hi" : Cmd String
perform 1 : Cmd number

"real world" exaple:

type alias Model = ()
type Msg = Fire | FireRockets

update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
  case msg of
    Fire ->
      ((), perform FireRockets)
    FireRockets ->
      Debug.crash "World ended:("
attempt : Result x msg -> Cmd msg

Similar to perform but takes Result msg and performs action only on Ok.

attempt (Ok 1) : Cmd number
attempt (Ok "I'm fine") : Cmd String
attempt (Err "Failed") == Cmd.none => True