Get updates via , Github, or RSS | About

Episode 14: Advanced Tasks Nov 10, 2016

Elm’s Task library gives you lots of options to combine Tasks of different types, execute them in a specific order, and change their result and error types. Mastering this library makes Tasks a pleasure to use.

Examples

update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
  case msg of
    DealHand ->
      let
        localTask =
          locallyStore updated
            |> Task.mapError LocallyStoreError
        remoteTask value =
          remotelyStore value model
            |> Task.mapError (RemotelyStoreError << httpErrorToString)
        cmd =
          localTask `andThen` remoteTask
            |> Task.perform StorageFail StorageSucceed
      in
        model ! [cmd]
    StorageFail error ->
      let
        updated = updateModelFromErrorType error model
      in
        updated ! []
    StorageSucceed value->
      model ! []