aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-05-05 08:11:49 +0100
committerAkshay <[email protected]>2020-05-05 08:11:49 +0100
commita180e06d4bba98e3bb60637ff714dff371a0d1e4 (patch)
tree4aa992512b0381560db6c992058cf00bffcd530d
parent2275ce14ee7bed99271fc8dc3dabab56d47a3138 (diff)
doc
-rw-r--r--readme.md56
1 files changed, 56 insertions, 0 deletions
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..86f134e
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,56 @@
1# cutlass
2
3> experimental auto-currying for rust functions
4
5### example
6
7this currently works only on nightly with the
8`type_alias_impl_trait` feature enabled.
9
10```rust
11#![feature(type_alias_impl_trait)]
12
13#[cutlass::curry]
14fn add(x: u32, y: u32, z: u32) -> u32 {
15 return x + y + z;
16}
17
18fn main() {
19 let plus_3 = add(1)(2);
20 let v: Vec<u32> = (1..=3).map(plus_3).collect();
21 assert_eq!(v, vec![4, 5, 6]);
22}
23```
24
25### how it works
26
27the `#[curry]` proc-macro expands the above `add` function to
28something like this (roughly):
29
30```rust
31type T0 = u32;
32type T1 = impl Fn(u32) -> T0;
33type T2 = impl Fn(u32) -> T1;
34fn add(x: u32) -> T2 {
35 return (move |y| move |z| x + y + z);
36}
37```
38
39### gotchas
40
41 - doesn't yet work for method functions (signatures with
42 `self`)
43 - the function has to have a return value
44 - works only on nightly with `type_alias_impl_trait`
45 enabled
46
47### testing
48
49test this crate with `cargo +nightly test`.
50
51to view macro expansions, install `cargo-expand` and run `cargo expand
52--test <test name>`. expand `tests/smoke.rs` for example:
53
54```
55cargo expand --test smoke
56```