pub fn fold_effect<T, A, Env, F, Eff>(
items: Vec<T>,
init: A,
f: F,
) -> BoxedEffect<A, AnalysisError, Env>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 foldinit- The initial accumulator valuef- 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?;