Skip to content
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.result #47

Merged
merged 5 commits into from
Apr 22, 2024
Merged

Add Task.result #47

merged 5 commits into from
Apr 22, 2024

Conversation

lukewilliamboswell
Copy link
Collaborator

Zulip discussion

Test program

app "test"
    packages { pf: "../platform/main.roc" }
    imports [
        pf.Stdout,
        pf.Task.{ Task },
        pf.Http.{ Request, Response },
        pf.Utc,
    ]
    provides [main] to pf

main : Request -> Task Response []
main = \req ->

    result = checkFile "bad" |> Task.result!

    when result is
        Ok Good -> Task.ok { status: 200, headers: [], body: Str.toUtf8 "GOOD" }
        Ok Bad -> Task.ok { status: 200, headers: [], body: Str.toUtf8 "BAD" }
        Err IOError -> Task.ok { status: 200, headers: [], body: Str.toUtf8 "ERROR" }     

checkFile : Str -> Task [Good, Bad] [IOError]
checkFile = \str ->
    if str == "good" then 
        Task.ok Good 
    else if str == "bad" then 
        Task.ok Bad 
    else 
        Task.err IOError

Copy link
Collaborator

@Anton-4 Anton-4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @lukewilliamboswell! Can you add two small tests?

@lukewilliamboswell
Copy link
Collaborator Author

@Anton-4 I've added the program as a test, and included in the expect scripts.

@lukewilliamboswell
Copy link
Collaborator Author

The CI failure with the below suggests the latest nightly hasn't been updated. We can re-run CI when nightly includes support for suffixed when expressions which was merged in roc-lang/roc#6649

A suffixed expression did not get desugared somehow: Suffixed(
    Var {
        module_name: "Task",
        ident: "result",
    },
)

@Anton-4 Anton-4 merged commit 293a73f into main Apr 22, 2024
2 checks passed
@Anton-4 Anton-4 deleted the task-result branch April 22, 2024 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants