Skip to content

Instantly share code, notes, and snippets.

@liamcurry
Last active May 11, 2016 04:08
Show Gist options
  • Save liamcurry/f6c3ea8e5ff3a1d4c0e08f2e4fee2e37 to your computer and use it in GitHub Desktop.
Save liamcurry/f6c3ea8e5ff3a1d4c0e08f2e4fee2e37 to your computer and use it in GitHub Desktop.
applyMessages : Model -> List Msg -> ( Model, Cmd Msg )
applyMessages model msgs =
let
reduce : Msg -> ( Model, List (Cmd Msg) ) -> ( Model, List (Cmd Msg) )
reduce msg ( oldModel, cmds ) =
let
( newModel, cmd ) =
update msg oldModel
in
( newModel, cmd :: cmds )
results : ( Model, List (Cmd Msg) )
results =
List.foldl reduce ( model, [] ) msgs
in
( results |> fst
, results |> snd |> Cmd.batch
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment