Stream: contributing

Topic: idiomatic Roc get


view this post on Zulip Anton (May 08 2024 at 18:41):

Can the style here be improved/more idiomatic?

app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.11.0/SY4WWMhWQ9NvQgvIthcv15AUeA7rAIJHAHgiaSHGhdY.tar.br" }

import pf.Http
import pf.Task exposing [Task]
import pf.Stdout
import pf.Stderr

main =
    request = {
        method: Get,
        headers: [],
        url: "http://localhost:8080",
        mimeType: "",
        body: [],
        timeout: TimeoutMilliseconds 5000,
    }

    sendResult =
        Http.send request
            |> Task.result!

    processedSendResult =
        Result.try sendResult Http.handleStringResponse

    when processedSendResult is
        Ok body ->
            Stdout.line "Response body: $(body)."

        Err err ->
            Stderr.line (Inspect.toStr err)

view this post on Zulip Luke Boswell (May 08 2024 at 19:24):

I think I would use something like
when Http.send request |> Task.result |> Task.map! Http.handleStringResponse is, though I'll caveat that by saying that I'm on my phone and havent tested it or checked the types work.

view this post on Zulip Anton (May 10 2024 at 09:12):

Thanks Luke, I'll give that a try :)


Last updated: Jul 06 2025 at 12:14 UTC