-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Task.seq
and Task.forEach
#19
base: main
Are you sure you want to change the base?
Conversation
Posted in zulip
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the description for seq
doesn't fit.
## Apply a task repeatedly to a list of items, and return a list of the resulting values | ||
## | ||
## ``` | ||
## authors : List ID | ||
## getAuthor : ID -> Task Author [DbError] | ||
## | ||
## getAuthors : Task (List Author) [DbError] | ||
## getAuthors = Task.list authors getAuthor | ||
## ``` | ||
## | ||
seq : List (Task ok err) -> Task (List ok) err | ||
seq = \tasks -> | ||
List.walk tasks (Task.ok []) \state, task -> | ||
value <- task |> Task.await | ||
|
||
state |> Task.map \values -> List.append values value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the comment doesn't fit the implementation. It seems to me, Task.seq
actually converts a List (Task ok err)
to a Task (List ok) err
.
Or is there a Task.list
function missing here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @RMailaender
This implementation is copied from basic-cli. https://github.com/roc-lang/basic-cli/blob/307f1f91d984ac966cca75a40d403bdced1f05a6/platform/Task.roc#L227
I think if we are going to change this, we should discuss this further on zulip, and try to keep the API for basic-cli and basic-web server aligned.
c4cf702
to
14173e6
Compare
This was recently added to basic-cli in roc-lang/basic-cli#156