How to migrate 0.16 code using Effects.task to equivalent 0.17 code

298 views
Skip to first unread message

Janis Voigtländer

unread,
May 19, 2016, 6:38:18 AM5/19/16
to elm-d...@googlegroups.com

Questions how to do migrate 0.16 code involving Effects.task to 0.17 have come up repeatedly now, so I thought it makes sense to write down general advice about this. Below is my advice. In each of the cases below, I first give a snippet of 0.16 code and what I advise to use as equivalent 0.17 code. In each case, when the 0.16 version has some type of the form Effects SomeType, the 0.17 code I give has type Cmd SomeType (for the same SomeType, of course).

So, here goes:

If in 0.16 you had:

task |> Task.toMaybe |> Effects.task

use the following in 0.17:

task |> Task.perform (always Nothing) Just

If in 0.16 you had:

task |> Task.toMaybe |> Task.map action |> Effects.task

use the following in 0.17:

task |> Task.toMaybe |> Task.perform never action

If in 0.16 you had:

task |> Task.toResult |> Effects.task

use the following in 0.17:

task |> Task.perform Err Ok

If in 0.16 you had:

task |> Task.toResult |> Task.map action |> Effects.task

use the following in 0.17:

task |> Task.toResult |> Task.perform never action

The function never used in two places above is from http://package.elm-lang.org/packages/elm-community/basics-extra.

Janis Voigtländer

unread,
May 19, 2016, 7:02:48 AM5/19/16
to elm-d...@googlegroups.com

Oh, and of course, if task was something not involving Task.toMaybe or Task.toResult (for, example, task could have been simply Task.succeed ...), then:

If in 0.16 you had:

task |> Effects.task

use the following in 0.17:

task |> Task.perform never identity

Frederick Yankowski

unread,
May 19, 2016, 12:10:13 PM5/19/16
to Elm Discuss

Janis Voigtländer

unread,
May 19, 2016, 1:02:19 PM5/19/16
to elm-d...@googlegroups.com
Cool. I've made a pull request streamlining the recommendation a bit, and covering an additional case.

2016-05-19 18:10 GMT+02:00 Frederick Yankowski <fre...@gmail.com>:

--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages