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: avoiding `{} <-` `|> await` boilerplate

Anton-4 opened this issue · comments

We should make an example for this once we figure it out ourselves :p

Example of a problematic case:

{} <- log "Extracting current rust version from rust-toolchain.toml..." |> await
{ stable: currentStable, nightly: currentNightly } <- getCurrentVersionsFromToml |> await
{} <- log "Found versions:\n\t- stable: \(versionToStr currentStable)\n\t- nightly with date: \(dateToStr currentNightly)" |> await
# TODO Task.map to avoid repeated `{} <-`?
{} <- log "Searching for nightly matching stable-\(newRustVersion)..." |> await

newNightly <-
    findMatchingNigthly (versionFromStr newRustVersion) currentNightly
    |> await

{} <- log "New nightly: nightly-\(dateToStr newNightly)" |> await

TODO can we avoid boiler plate of `{} <-` and `await` here?
{} <-
    Path.fromStr "rust-toolchain.toml"
    |> updateToml newRustVersion
    |> await

{} <-
    Path.fromStr "examples/platform-switching/rust-platform/rust-toolchain.toml"
    |> updateToml newRustVersion
    |> await

{} <-
    Path.fromStr "Earthfile"
    |> updateEarthFile newRustVersion
    |> await