Stream: beginners

Topic: ✔ Result to Task utility


view this post on Zulip Chris Duncan (Oct 08 2022 at 06:33):

Is a function that maps a Result to a Task in cli-platform? I would imagine there would be one that maps Ok to Task.succeed and Err to Task.fail.

view this post on Zulip Brendan Hansknecht (Oct 08 2022 at 06:41):

I am pretty sure the answer is currently no, but it probably should be sdded

view this post on Zulip Brendan Hansknecht (Oct 08 2022 at 06:43):

Something like:

fromResult = \result ->
    when result is
        Ok x -> Task.succeed x
        Err e -> Task.fail e

view this post on Zulip Richard Feldman (Oct 08 2022 at 06:44):

sounds reasonable! If anyone would like to make a PR to add it, here's the file where it would go:

https://github.com/roc-lang/roc/blob/main/examples/interactive/cli-platform/Task.roc

view this post on Zulip Prajwal S N (Oct 08 2022 at 07:00):

@Richard Feldman would it be better to put it in https://github.com/roc-lang/roc/blob/main/examples/interactive/cli-platform/InternalTask.roc? Since fromEffectalso sits there...

view this post on Zulip Prajwal S N (Oct 08 2022 at 07:02):

The tutorial says Tasks have two type params (Task {} *), but the definitions in Task.roc all have three - Task ok err fx. What is this fx?

view this post on Zulip Brian Carroll (Oct 08 2022 at 08:46):

No, fromEffect is an internal function that users shouldn't directly access. Roc has managed effects so they are treated very specially.
This new fromResult function is very different. It has nothing to do with effects and there is no reason to make it internal.

view this post on Zulip Brian Carroll (Oct 08 2022 at 08:51):

Regarding fx, the docs should be updated to include this.

Each different effect in the platform has its own tag that goes in this part of the type.

So the type system is able to keep track of which effects are used in which parts of the app code. This is useful information for the app developer. If some effect goes wrong, you can find the problem easily.

view this post on Zulip Chris Duncan (Oct 08 2022 at 11:46):

@Richard Feldman, I can take that on. The only documentation one adds to the platform is the comment above the function definition? Are there other places to add documention for a platform's API?

view this post on Zulip Richard Feldman (Oct 08 2022 at 13:14):

you're correct - that's the only place!

view this post on Zulip Chris Duncan (Oct 09 2022 at 01:00):

Here's the PR:
https://github.com/roc-lang/roc/pull/4265

view this post on Zulip Notification Bot (Oct 09 2022 at 13:15):

Chris Duncan has marked this topic as resolved.


Last updated: Jul 06 2025 at 12:14 UTC