// code clean format with only run once expensive function
code clean format with only run once expensive function
code clean format with only run once expensive function
fn generate_workout2(intensity: u32, random_number: u32) {
    // let expensive_result = simulated_expensive_calculation(intensity);
    // closure function return value "num"
    // only run when call expensive_closure
    // like () => {} in js
    let expensive_closure = |num: u32| -> u32 {
        println!("calculating slowly...");
        thread::sleep(Duration::from_secs(2));
        num
    };
    if intensity < 25 {
        println!("Today, do {} pushups!", expensive_closure(intensity));
        println!("Next, do {} situps!", expensive_closure(intensity));
    } else {
        if random_number == 3 {
            println!("Take a break today! Remember to stay hydrated!");
        } else {
            println!("Today, run for {} minutes!", expensive_closure(intensity));
        }
    }
}
fn generate_workout2 ( intensity : u32 , random_number : u32 ) { // let expensive_result = simulated_expensive_calculation(intensity); // closure function return value "num" // only run when call expensive_closure // like () => {} in js let expensive_closure = | num : u32 | -> u32 { println ! ( " " ) ; thread :: sleep ( Duration :: from_secs ( 2 ) ) ; num } ; if intensity < 25 { println ! ( " " expensive_closure ( intensity ) ) ; println ! ( " " expensive_closure ( intensity ) ) ; } else { if random_number == 3 { println ! ( " " ) ; } else { println ! ( " " expensive_closure ( intensity ) ) ; } } }
code clean format with only run once expensive function
code clean format with only run once expensive function
intensity
u32
random_number
u32