Logo

Programming-Idioms

History of Idiom 37 > diff from v25 to v26

Edit summary for version 26 by Miquel:
[Rust] looks like other samples do not include a main() function either.

Version 25

2018-01-28, 08:21:20

Version 26

2018-01-28, 08:25:16

Idiom #37 Currying

Transform a function that takes multiple arguments into a function for which some of the arguments are preset.

Idiom #37 Currying

Transform a function that takes multiple arguments into a function for which some of the arguments are preset.

Extra Keywords
curry
Extra Keywords
curry
Code
fn add(a: u32, b: u32) -> u32 {
    a + b
}
fn main() {
    let add5 = move |x| add(5, x);
    println!("{}", add5(2));
}
Code
fn add(a: u32, b: u32) -> u32 {
    a + b
}

let add5 = move |x| add(5, x);
 
Doc URL
https://doc.rust-lang.org/book/first-edition/closures.html
Doc URL
https://doc.rust-lang.org/book/first-edition/closures.html