Closures in Rust are anonymous functions that can capture variables from their environment. They are similar to functions but have some unique properties that make them powerful and flexible. Closures are often used for short, simple operations and can be defined in a very concise way.
Your task is to complete the implementation of the following closures:
add_closure
: This closure should return the sum of two integers.subtract_closure
: This closure should return the difference between two integers.multiply_closure
: This closure should return the product of two integers.i32
.i32
.Here are some hints to help you solve the exercise:
|a, b|
syntax to define the parameters of the closure.a
and b
.pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| a+b; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a,b| a-b; let multiply_closure = |a,b| a*b; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. (add_closure, subtract_closure, multiply_closure)}// Example usagepub fn main() { let (add, subtract, multiply) = create_closures(); // Example tests assert_eq!(add(3, 4), 7); // Expected: 7 assert_eq!(subtract(10, 4), 6); // Expected: 6 assert_eq!(multiply(3, 5), 15); // Expected: 15}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| a + b; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| a - b; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| a * b; (add_closure, subtract_closure, multiply_closure)}// Example usagepub fn main() { let (add, subtract, multiply) = create_closures(); // Example tests assert_eq!(add(3, 4), 7); // Expected: 7 assert_eq!(subtract(10, 4), 6); // Expected: 6 assert_eq!(multiply(3, 5), 15); // Expected: 15}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { // Step 1: Implement here a + b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| { a - b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| { a * b }; (add_closure, subtract_closure, multiply_closure)}// Example usagepub fn main() { let (add, subtract, multiply) = create_closures(); // Example tests assert_eq!(add(3, 4), 7); // Expected: 7 assert_eq!(subtract(10, 4), 6); // Expected: 6 assert_eq!(multiply(3, 5), 15); // Expected: 15}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { // Step 1: Implement here a + b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| { a - b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| { a * b }; (add_closure, subtract_closure, multiply_closure)}// Example usagepub fn main() { let (add, subtract, multiply) = create_closures(); // Example tests assert_eq!(add(3, 4), 7); // Expected: 7 assert_eq!(subtract(10, 4), 6); // Expected: 6 assert_eq!(multiply(3, 5), 15); // Expected: 15}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { a + b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| { a - b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| { a * b }; (add_closure, subtract_closure, multiply_closure)}// Example usagepub fn main() { let (add, subtract, multiply) = create_closures(); // Example tests assert_eq!(add(3, 4), 7); // Expected: 7 assert_eq!(subtract(10, 4), 6); // Expected: 6 assert_eq!(multiply(3, 5), 15); // Expected: 15}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| a + b; let subtract_closure = |a, b| a - b; let multiply_closure = |a, b| a * b; (add_closure, subtract_closure, multiply_closure)}// Example usagepub fn main() { let (add, subtract, multiply) = create_closures(); // Example tests assert_eq!(add(3, 4), 7); // Expected: 7 assert_eq!(subtract(10, 4), 6); // Expected: 6 assert_eq!(multiply(3, 5), 15); // Expected: 15}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { a + b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| { a - b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| { a * b }; (add_closure, subtract_closure, multiply_closure)}// Example usagepub fn main() { let (add, subtract, multiply) = create_closures(); // Example tests assert_eq!(add(3, 4), 7); // Expected: 7 assert_eq!(subtract(10, 4), 6); // Expected: 6 assert_eq!(multiply(3, 5), 15); // Expected: 15}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { a + b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| { a - b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| { a * b }; (add_closure, subtract_closure, multiply_closure)}// Example usagepub fn main() { let (add, subtract, multiply) = create_closures(); // Example tests assert_eq!(add(3, 4), 7); // Expected: 7 assert_eq!(subtract(10, 4), 6); // Expected: 6 assert_eq!(multiply(3, 5), 15); // Expected: 15}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { // Step 1: Implement here a + b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| { a - b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| { a * b }; (add_closure, subtract_closure, multiply_closure)}// Example usagepub fn main() { let (add, subtract, multiply) = create_closures(); // Example tests assert_eq!(add(3, 4), 7); // Expected: 7 assert_eq!(subtract(10, 4), 6); // Expected: 6 assert_eq!(multiply(3, 5), 15); // Expected: 15}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { // Step 1: Implement here a + b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| { a - b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| {a * b}; (add_closure, subtract_closure, multiply_closure)}// Example usagepub fn main() { let (add, subtract, multiply) = create_closures(); // Example tests assert_eq!(add(3, 4), 7); // Expected: 7 assert_eq!(subtract(10, 4), 6); // Expected: 6 assert_eq!(multiply(3, 5), 15); // Expected: 15}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { // Step 1: Implement here a + b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| { a - b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| { a * b }; (add_closure, subtract_closure, multiply_closure)}// Example usagepub fn main() { let (add, subtract, multiply) = create_closures(); // Example tests assert_eq!(add(3, 4), 7); // Expected: 7 assert_eq!(subtract(10, 4), 6); // Expected: 6 assert_eq!(multiply(3, 5), 15); // Expected: 15}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { // Step 1: Implement here a + b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| { // Step 1: Implement here a - b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| { // Step 1: Implement here a * b }; (add_closure, subtract_closure, multiply_closure)}// Example usagepub fn main() { let (add, subtract, multiply) = create_closures(); // Example tests assert_eq!(add(3, 4), 7); // Expected: 7 assert_eq!(subtract(10, 4), 6); // Expected: 6 assert_eq!(multiply(3, 5), 15); // Expected: 15}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { // Step 1: Implement here a + b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| { a - b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| { a * b }; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { // Step 1: Implement here return a + b; }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| a - b; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| a * b; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { a + b }; let subtract_closure = |a, b| { a - b }; let multiply_closure = |a, b| { a * b }; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { return a+b; }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure=|a,b|{ return a-b; }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure=|a,b|{return a*b; }; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { // Step 1: Implement here a + b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| { a - b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| { a * b }; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { return a + b }; let subtract_closure = |a, b| { return a - b }; let multiply_closure = |a, b| { return a * b }; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { // Step 1: Implement here a+b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| { // Step 1: Implement here a-b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| { // Step 1: Implement here a*b }; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { a+b }; let subtract_closure = |a, b|{ a-b }; let multiply_closure = |a, b| { a*b }; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a: i32, b: i32| a + b; let subtract_closure = |a: i32, b: i32| a - b; let multiply_closure = |foo: i32, bar: i32| foo * bar; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { // Step 1: Implement here a + b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| { a - b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| { a * b }; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { // Step 1: Implement here a + b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| { a - b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| { a * b }; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { // Step 1: Implement here a + b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| { // Step 1: Implement here a - b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| { // Step 1: Implement here a * b }; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { // Step 1: Implement here a+b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a,b|{ a-b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a,b| { a*b }; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { a + b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| { a - b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| { a * b }; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { a + b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| { a - b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| { a * b }; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a:i32, b:i32| -> i32{ // Step 1: Implement here a + b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| { // Step 1: Implement here a - b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| { // Step 1: Implement here a * b }; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { a + b }; let subtract_closure = |a, b| { a - b }; let multiply_closure = |a, b| { a * b }; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { // Step 1: Implement here a + b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = | a, b| { a - b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = | a, b| { a * b }; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { a + b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| { a - b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| { a * b }; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { a + b }; let subtract_closure = |a, b| { a - b }; let multiply_closure = |a, b| { a * b }; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { a + b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| { a - b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| { a * b }; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { // Step 1: Implement here a + b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| a - b; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| a * b; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a: i32, b: i32| -> i32 { // Step 1: Implement here a + b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a: i32, b: i32| -> i32 { a - b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a: i32, b: i32| -> i32 { a * b }; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { // Step 1: Implement here a + b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| { // Step 1: Implement here a - b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| { // Step 1: Implement here a * b }; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| a+b; let subtract_closure = |a, b| a-b; let multiply_closure = |a, b| a*b; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { // Step 1: Implement here a + b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| { a - b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| { a * b }; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { // Step 1: Implement here a+b }; let subtract_closure = |a, b| { a-b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values.let multiply_closure = |a, b| { a*b}; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { // Step 1: Implement here a + b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| { // Step 1: Implement here a - b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| { // Step 1: Implement here a * b }; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { // Step 1: Implement here return a + b; }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| a - b; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| a * b; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { // Step 1: Implement here return a + b; }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| a - b; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| a * b; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a: i32, b: i32| { // Step 1: Implement here return a + b; }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a: i32, b: i32| { // Step 1: Implement here return a - b; }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a: i32, b: i32| { // Step 1: Implement here return a * b; }; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { // Step 1: Implement here a + b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| a - b; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| a * b; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { // Step 1: Implement here a+b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a ,b| { a-b }; let multiply_closure = |a , b| { a*b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { // Step 1: Implement here a+b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a ,b| { a-b }; let multiply_closure = |a , b| { a*b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a:i32, b:i32| a + b; let subtract_closure = |a:i32, b:i32| a - b; let multiply_closure = |a:i32, b:i32| a * b; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { // Step 1: Implement here a + b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| { // Step 1: Implement here a - b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| { // Step 1: Implement here a * b }; (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a: i32, b: i32| { a+b }; // Step 2: let subtract_closure = |a: i32, b:i32| a - b; // Create the `subtract_closure` closure that subtracts two `i32` values. // Step 3: let multiply_closure = |a: i32, b: i32| a * b; // Create the `multiply_closure` closure that multiplies two `i32` values. (add_closure, subtract_closure, multiply_closure)}
pub fn create_closures() -> ( impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32, impl Fn(i32, i32) -> i32,) { let add_closure = |a, b| { // Step 1: Implement here a + b }; // Step 2: // Create the `subtract_closure` closure that subtracts two `i32` values. let subtract_closure = |a, b| { a - b }; // Step 3: // Create the `multiply_closure` closure that multiplies two `i32` values. let multiply_closure = |a, b| { a * b }; (add_closure, subtract_closure, multiply_closure)}