Skip to main content

counting_effect

Function counting_effect 

Source
pub fn counting_effect<'a, V, W, E, F>(
    counter: &'a EffectCounter,
    f: F,
) -> impl Fn(&V) -> Result<W, E> + 'a
where F: Fn(&V) -> Result<W, E> + 'a, V: 'a,
Expand description

Helper function to create a counting effectful function for testing

Returns a closure that increments the counter each time it’s called, then applies the provided function.

§Example

let counter = EffectCounter::new();
let counting_fn = counting_effect(&counter, |x: &i32| {
    if *x > 0 { Ok(*x) } else { Err("negative") }
});

// Use counting_fn in traverse
let result = pattern.traverse_result(counting_fn);

// Check how many times the function was called
assert_eq!(counter.count(), expected_count);