Skip to main content

fold_effect

Function fold_effect 

Source
pub fn fold_effect<T, A, Env, F, Eff>(
    items: Vec<T>,
    init: A,
    f: F,
) -> BoxedEffect<A, AnalysisError, Env>
where T: Send + 'static, A: Send + Clone + 'static, Env: Clone + Send + Sync + 'static, F: Fn(A, T) -> Eff + Send + Sync + 'static, Eff: Effect<Output = A, Error = AnalysisError, Env = Env> + Send + 'static,
Expand description

Fold a collection with an effectful accumulator.

This combinator reduces a collection using an effectful fold function, starting with an initial value.

§Arguments

  • items - The collection to fold
  • init - The initial accumulator value
  • f - A function that takes (accumulator, item) and produces an effect

§Returns

An effect that produces the final accumulated value.

§Example

let files = vec!["a.rs", "b.rs"];
let effect = fold_effect(files, 0usize, |total, path| {
    read_file_effect(path.into()).map(move |content| total + content.len())
});
let total_bytes = effect.run(&env).await?;