1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/// Creates a `CFn` (boxed `Fn`) from a nullary (0-argument) closure.
///
/// The resulting `CFn` will take a dummy argument (e.g., `()`) which it ignores,
/// then calls the original nullary closure.
///
/// # Examples
/// ```
/// use monadify::fn0; // Macro import
/// use monadify::function::CFn; // For type annotation if needed
///
/// let get_number = fn0!(|| 42);
/// let result: i32 = get_number.call(()); // Call with a dummy unit argument
/// assert_eq!(result, 42);
///
/// let greet = fn0!(|| "Hello".to_string());
/// assert_eq!(greet.call(()), "Hello");
/// ```
/// Creates a `CFn` (boxed `Fn`) from a unary (1-argument) closure.
///
/// This is a convenience macro for `CFn::new(closure)`.
///
/// # Examples
/// ```
/// use monadify::fn1;
/// use monadify::function::CFn;
///
/// let add_one = fn1!(|x: i32| x + 1);
/// assert_eq!(add_one.call(5), 6);
///
/// let to_string_fn = fn1!(|x: i32| x.to_string());
/// assert_eq!(to_string_fn.call(10), "10");
/// ```
/// Creates a curried function of two arguments, wrapped in `CFn`.
///
/// Given a closure `|x| |y| expr`, `fn2!` transforms it into
/// `move |x| CFn::new(move |y| closure(x)(y))`.
/// The outer function takes `x` and returns a `CFn` that takes `y`.
///
/// # Examples
/// ```
/// use monadify::fn2;
/// use monadify::function::CFn;
///
/// let curried_add = fn2!(|x: i32| move |y: i32| x + y);
///
/// let add_5_fn = curried_add(5); // add_5_fn is CFn<i32, i32>
/// assert_eq!(add_5_fn.call(10), 15); // Calls the inner closure with y = 10
///
/// assert_eq!(curried_add(3).call(7), 10);
/// ```
/// Creates a curried function of three arguments, wrapped in nested `CFn`s.
///
/// Given a closure `|x| |y| |z| expr`, `fn3!` transforms it into
/// `move |x| CFn::new(move |y| CFn::new(move |z| closure(x)(y)(z)))`.
///
/// # Examples
/// ```
/// use monadify::fn3;
/// use monadify::function::CFn;
///
/// let curried_add3 = fn3!(|x: i32| move |y: i32| move |z: i32| x + y + z);
///
/// let add_5_and_10_fn = curried_add3(5).call(10); // add_5_and_10_fn is CFn<i32, i32>
/// assert_eq!(add_5_and_10_fn.call(20), 35);
///
/// assert_eq!(curried_add3(1)(2).call(3), 6);
/// ```