Expand description
Scala’s Placeholder Syntax for Rust.
use placeholder_closure::λ;
let xs = xs.into_iter().map(λ!($ + 1)).collect::<Vec<_>>();§How it works
The λ! (or lambda!) macro replaces 0 or more $ characters with closure arguments.
let f = λ!($ + 1);will be:
let f = |__0| __0 + 1;§Constructing move closures
You can also construct move closures.
fn dot<F: FnOnce(Y) -> Z, G: FnOnce(X) -> Y, X, Y, Z>(f: F, g: G) -> impl FnOnce(X) -> Z {
λ!(move { f(g($)) })
}