etaque/elm-response/3.1.0

Response

Response utilities for Elm Architecture. Build responses from tasks, pipe them, map over.

Construct

type alias Response model msg =
( model, Cmd msg )

A response is an updated model and some cmd.

res : model -> Cmd msg -> Response model msg

Canonical usage: construct a result from model and cmd.

taskRes : model -> (Result x a -> msg) -> Task x a -> Response model msg

Construct a response from a model and task.

withCmd : Cmd a -> m -> Response m a

Construct a result from model and cmd, flipped for piping:

{ model | foo = bar }
    |> withCmd someCmd
withCmds : List (Cmd a) -> m -> Response m a

Construct a result from model and multiple cmds, flipped for piping:

{ model | foo = bar }
    |> withCmds [ someCmd1, someCmd1 ]
withTask : (Result x a -> msg) -> Task x a -> model -> Response model msg

Construct a result from model and task, flipped for piping:

{ model | foo = bar }
    |> withTask someTask
withNone : m -> Response m a

Construct a result from model without cmd, flipped for piping:

{ model | foo = bar }
    |> withNone
pure : m -> Response m a

Synonym for withNone (for those with a personal preference).

pure { model | foo = bar }

Transform

mapModel : (m -> n) -> Response m a -> Response n a

Map over model.

mapCmd : (a -> b) -> Response m a -> Response m b

Map over cmd.

mapBoth : (m -> n) -> (a -> b) -> Response m a -> Response n b

Map over model and cmd.

andThen : (m -> Response m a) -> Response m a -> Response m a

Sequence one update after another.

update1 : Model -> Response Model (Cmd Msg)
update2 : Model -> Response Model (Cmd Msg)
update3 : Model -> Response Model (Cmd Msg)


update1 model
|> andThen update2
|> andThen update3