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: pattern matching on `Task`

Anton-4 opened this issue · comments

It may be tempting to try pattern matching (similar to result) like this:

when Stdin.line is
    Ok (Input str) -> str
    _ -> "" 

But what you actually want here is:

Task.map
    Stdin.line
    \readInput ->
        when readInput is
            Input str -> str
            End -> ""

This definitely feels worth an example.
I recommend doing one with Stdin.line and something like Env.cwd (with Task.attempt).