roc-lang / examples

All kinds of Roc examples

Home Page:https://www.roc-lang.org/examples

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

example suggestion: several `Task.loop` examples

Anton-4 opened this issue · comments

I would love to give this a try. @Anton-4, could you please assign it to me?

From the links you mentioned, I think the simplest base example is this one: https://github.com/roc-lang/basic-cli/blob/main/examples/piping.roc

My idea is to show how to process the input line by line, but show also the case with an error. It could be, for example, reading a series of numbers from stdin, one per text line, converting every line into a Num, and keeping (and printing) a cumulative sum of the numbers. If the line is not a number, the loop is supposed to return a Task.err.

What do you think?

Sounds good to me.

Would you add the example for Task.loop to https://www.roc-lang.org/examples/Tasks/README.html or should I create a new one?

I think we should create a new one. It is better to keep them smaller and focussed. That example is much larger to show how to bring things together, specifically for error handling and more of an introduction.