CompetitiveProgramming/src/bin/test.rs

10 lines
251 B
Rust
Raw Permalink Normal View History

2024-02-27 11:42:51 +08:00
// Returns a function that adds `y` to its input
fn make_adder_function(y: i32) -> impl Fn(i32) -> i32 {
let closure = move |x: i32| { x + y };
closure
}
2024-01-18 12:40:12 +08:00
fn main() {
2024-02-27 11:42:51 +08:00
let plus_one = make_adder_function(1);
assert_eq!(plus_one(2), 3);
2024-01-18 12:40:12 +08:00
}