Modeling the update tuple as a Monad similar to Writer
Transform the Model the Cmd will be left untouched
Combine 2 Returns with a function
map2
(\modelA modelB -> { modelA | foo = modelB.foo })
retA
retBMap an Return into a Return containing a Model function
Transform the Model of and add a new Cmd to the queue
Map on the Cmd.
Create a Return from a given Model
Chain together expressions from Model to Return.
-- arbitrary function to demonstrate
foo : Model -> Return Msg Model
foo ({bar} as model) =
-- forking logic
if bar < 10
-- that side effects may be added
then (model, getAjaxThing)
-- that the model may be updated
else ({model | bar = model.bar - 2 }, Cmd.none)They are now chainable with andThen...
resulting : Return msg { model | bar : Int }
resulting =
myReturn `andThen` foo
`andThen` foo
`andThen` fooHere we changed up foo three times, but we can use any function of
type (a -> Return msg b).
Commands will be accumulated automatically as is the case with all functions in this library.
Same as >>| but the right hand Model is dropped
Same as >>| but the left hand Model is dropped
Go point free with andThen chaining. Looking at the example from andThen
resulting : Return msg { model | bar : Int }
resulting =
myReturn `andThen` foo
`andThen` foo
`andThen` foothis code roughly becomes:
doFoo3Times : { model | bar : Int } -> Return msg { model | bar : Int }
doFoo3Times =
foo >>> foo >>> fooCmdsConstruct a new Return from parts
Add a Cmd to a Return, the Model is uneffected
Construct a Return from a Cmd
Add a Cmd to a Return based on its Model, the Model will not be effected
Cmds