macro_rules! curry {
($($arg:ident ->)+ * $body:block) => { ... };
($($arg:ident ->)+ @$ret:ty $body:block) => { ... };
}
Expand description
Creates a curried function.
The given function definition should be specified in the form
(arg ->)+ (*|@return_type) {
function_body
}
No types are specified on the function parameters. An explicit return type can be specified
with a type preceded by an @
; specifying *
will deduce the return type. The macro will not
perform any type conversions.
§Examples
let add_3 = curry!(a -> b -> c -> * {
a + b + c
});
assert_eq!(add_3(13)(71)(26), 110);
let haiku = curry!(a -> b -> c -> @String {
let lines = vec![a, b, c];
lines.join("\n")
});
assert_eq!(haiku("The first cold shower")
("Even the monkey seems to want")
("A little coat of straw"),
"The first cold shower\n\
Even the monkey seems to want\n\
A little coat of straw");
ⓘ
let add_3 = curry!(a -> b -> c -> @usize {
a + b + c // error; evaluates to i32
});
assert_eq!(add_3(13)(71)(26), 110);