06 · Functions
Complete unary short lambdas
With a proven one-argument callback signature, underscore can stand for the whole parameter, including arithmetic and ordinary nested value calls. Nested callback slots get their own parameter. Blocks, explicit lambdas, collections and pipes remain scope boundaries.
On this page
With a proven one-argument callback signature, underscore can stand for the whole parameter, including arithmetic and ordinary nested value calls. Nested callback slots get their own parameter. Blocks, explicit lambdas, collections and pipes remain scope boundaries.
Complete example
Complete unary short lambdas.
22-unary-short-lambdas.zolo
// expected:
// 4
// 6
// Ana!
// 2
// 1
struct User { name: str }
fn format_name(name: str) -> str { name + "!" }
let doubled = [2, 3].map(_ * 2)
print(doubled[0])
print(doubled[1])
print([User { name: "Ana" }].map(format_name(_.name))[0])
// Each proved nested callback gets its own parameter.
let sizes = [[2, 3], [4]].map(_.map(_ + 1).len())
print(sizes[0])
print(sizes[1])
Rules and behavior
Function parameters and lambdas · Documentation
From a checkout of the repository:
zolo examples/features/05-functions/22-unary-short-lambdas.zolo
See also