Janiczek / cmd-extra / Cmd.Extra

A library providing pipeline-friendly Cmd operators.

Cmds

withNoCmd : model -> ( model, Platform.Cmd.Cmd msg )

Wraps the model with Cmd.none.

init : ( Model, Cmd Msg )
init =
    myModel
        |> withNoCmd

withCmd : Platform.Cmd.Cmd msg -> model -> ( model, Platform.Cmd.Cmd msg )

Wraps the model with given Cmd.

incrementAndPing : Model -> ( Model, Cmd Msg )
incrementAndPing model =
    { model | counter = model.counter + 1 }
        |> withCmd ping

withCmds : List (Platform.Cmd.Cmd msg) -> model -> ( model, Platform.Cmd.Cmd msg )

Wraps the model with given Cmds.

incrementAndPingTwice : Model -> ( Model, Cmd Msg )
incrementAndPingTwice model =
    { model | counter = model.counter + 1 }
        |> withCmds [ ping 1, ping 2 ]

addCmd : Platform.Cmd.Cmd msg -> ( model, Platform.Cmd.Cmd msg ) -> ( model, Platform.Cmd.Cmd msg )

Adds a new Cmd to an existing model-Cmd tuple.

( model, cmd )
    |> addCmd ping

addCmds : List (Platform.Cmd.Cmd msg) -> ( model, Platform.Cmd.Cmd msg ) -> ( model, Platform.Cmd.Cmd msg )

Adds new Cmds to an existing model-Cmd tuple.

( model, cmd )
    |> addCmds [ ping 1, ping 2 ]

andThen : (model -> ( model, Platform.Cmd.Cmd msg )) -> ( model, Platform.Cmd.Cmd msg ) -> ( model, Platform.Cmd.Cmd msg )

Allows your function that works on Model to work on (Model, Cmd Msg).

doFoo : Model -> (Model, Cmd Msg)
doBar : Model -> (Model, Cmd Msg)

model
    |> doFoo
    -- we have `(Model, Cmd Msg)` now, but `doBar` needs a `Model`
    -- so we use...
    |> andThen doBar