Skip to content

06 · Functions

Arguments from a record

Pass named fields with ..options. The record is evaluated once in source order; explicit arguments override expanded fields regardless of their position. Unknown labels and incompatible field types are errors.

On this page

Pass named fields with ..options. The record is evaluated once in source order; explicit arguments override expanded fields regardless of their position. Unknown labels and incompatible field types are errors.

Complete example

Arguments from a record.

01-record-arguments.zolo
Playground
struct ConnectionOptions { host: str, timeout: int }

fn connect(host: str, timeout wait: int, retries: int = 2) -> str =
    "{host}: timeout={wait}, retries={retries}"

let options = ConnectionOptions { host: "api.example.test", timeout: 30 }
let fast = connect(..options, timeout: 5)
let slow = connect(timeout: 60, ..options)
assert(fast == "api.example.test: timeout=5, retries=2")
assert(slow == "api.example.test: timeout=60, retries=2")
print(fast)
print(slow)

Reference

Reference · Source program

zolo run examples/features/40-syntax-fourth/01-record-arguments.zolo --no-cache

See also

Global index

Find your way through Zolo

Try an idea

Start here

9 results

9 results

enespt-br