Chadtech/return/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

Return2

This package makes it easier to build (module, Cmd msg), the typical result of an update function

With

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

Pack a cmd with your model

model
    |> withCmd cmd
withCmds : List (Cmd msg) -> model -> ( model, Cmd msg )

Pack multiple cmds with your model

model
    |> withCmds [ cmd0, cmd1 ]
withNoCmd : model -> ( model, Cmd msg )

Pack your model with no cmd

model
    |> withNoCmd
withModel : model -> Cmd msg -> ( model, Cmd msg )

Pack a model with your cmd. This is useful if the business logic for your command is more complicated than the business logic for your model

Close ->
    model.sessionId
        |> Ports.Close
        |> Ports.send
        |> withModel model

Add

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

Sometimes you need to add a cmd to an already packaged model and cmd.

(model, cmd0)
    |> addCmd cmd1


    -- == (model, Cmd.batch [ cmd1, cmd0 ])
addCmds : List (Cmd msg) -> ( model, Cmd msg ) -> ( model, Cmd msg )

Add many cmds to an already packaged model and cmd.

(model, cmd0)
    |> addCmds [ cmd1, cmd2 ]


    -- == (model, Cmd.batch [ cmd0, cmd1, cmd2 ])

Map

mapModel : (a -> b) -> ( a, Cmd msg ) -> ( b, Cmd msg )

If you need to transform just the model in a tuple, such as if you need to pack a submodel into the main model

loginModel
    |> Login.update subMsg
    |> mapModel (setPage model Page.Login)
mapCmd : (a -> b) -> ( model, Cmd a ) -> ( model, Cmd b )

If you need to transform just the cmd in a tuple, such as if you need to wrap a sub-modules msg type

loginModel
    |> Login.update subMsg
    |> mapCmd LoginMsg

Get

model : ( model, Cmd msg ) -> model

Ideally you wouldnt have to deconstruct a tupled model and cmd, but if you need to, this function does it.

Return2.model (model, cmd) == model
cmd : ( model, Cmd msg ) -> Cmd msg

Get the cmd of an already tupled model and cmd.

Return2.cmd (model, cmd) == cmd