curry-macro
Have fun currying using Rust's native closure syntax.
Example
You can curry an add function that adds two numbers.
First, import the curry macro:
use curry;
Then, you have three forms of function definitions to choose from:
- Simplest form, without any type annotations. You need to use the curried function so that the rust compiler can infer the input and return types for you:
let add = curry!;
assert_eq!;
- With input type annotations:
let add = curry!;
- With input and return type annotations and a block as function body
let add = curry!;
The above three functions work the same:
// You can generate intermediate functions that are partially applied:
let add1_to = add;
let sum = add1_to;
assert_eq!;
// You can also can apply all arguments at once:
let sum = add;
assert_eq!;
Credits
Big thanks to Korede-TA for his awesome curry-macro.
License
MIT