roc/crates/cli/tests/benchmarks/closure.roc
2025-01-15 19:55:27 -06:00

50 lines
1,023 B
Text

app [main!] { pf: platform "platform/main.roc" }
main! : {} => {}
main! = \{} ->
closure1({})
|> Result.try(closure2)
|> Result.try(closure3)
|> Result.try(closure4)
|> Result.with_default({})
# ---
closure1 : {} -> Result {} []
closure1 = \_ ->
Ok(foo(to_unit_borrowed, "a long string such that it's malloced"))
|> Result.map_ok(\_ -> {})
to_unit_borrowed = \x -> Str.count_utf8_bytes(x)
foo = \f, x -> f(x)
# ---
closure2 : {} -> Result {} []
closure2 = \_ ->
x : Str
x = "a long string such that it's malloced"
Ok({})
|> Result.map_ok(\_ -> x)
|> Result.map_ok(to_unit)
to_unit = \_ -> {}
# # ---
closure3 : {} -> Result {} []
closure3 = \_ ->
x : Str
x = "a long string such that it's malloced"
Ok({})
|> Result.try(\_ -> Ok(x) |> Result.map_ok(\_ -> {}))
# # ---
closure4 : {} -> Result {} []
closure4 = \_ ->
x : Str
x = "a long string such that it's malloced"
Ok({})
|> Result.try(\_ -> Ok(x))
|> Result.map_ok(\_ -> {})