Skip to content

Instantly share code, notes, and snippets.

@esad
Last active March 20, 2016 17:21
Show Gist options
  • Save esad/5be30a950e7c3b8190cb to your computer and use it in GitHub Desktop.
Save esad/5be30a950e7c3b8190cb to your computer and use it in GitHub Desktop.
module Response where
import List
import Effects exposing (Effects)
import Task exposing (Task)
import Result exposing (Result)
type alias Response model action = (model, Effects action)
withModel : Effects a -> m -> Response m a
withModel e m =
(m, e)
noFx : m -> Response m a
noFx =
Effects.none
|> withModel
taskFx : Task Effects.Never a -> m -> Response m a
taskFx task =
Effects.task task
|> withModel
anotherActionFx : a -> m -> Response m a
anotherActionFx action =
Task.succeed action
|> Effects.task
|> withModel
actionTaskFx : (Result e s -> a) -> Task e s -> m -> Response m a
actionTaskFx action task =
task
|> Task.toResult
|> Task.map action
|> Effects.task
|> withModel
andFx : (m -> Response m a) -> (m -> Response m a) -> (m -> Response m a)
andFx e1 e2 x =
(x, List.map snd [e1 x, e2 x] |> Effects.batch )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment