From 088b3df79ae82d599975149b28160b16b18b7c1f Mon Sep 17 00:00:00 2001 From: Thomas Hurst Date: Wed, 12 Sep 2018 20:23:23 +0100 Subject: [PATCH] Replace fold/reduce over Result::and with collect Not only is this tidier, but it avoids making these iterators Rayon-specific. --- components/imageproc/src/lib.rs | 4 +--- components/site/src/lib.rs | 18 ++++++------------ 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/components/imageproc/src/lib.rs b/components/imageproc/src/lib.rs index db553a6c..68a383a0 100644 --- a/components/imageproc/src/lib.rs +++ b/components/imageproc/src/lib.rs @@ -363,9 +363,7 @@ impl Processor { let target = self.resized_path.join(Self::op_filename(*hash, op.collision_id)); op.perform(&self.content_path, &target) .chain_err(|| format!("Failed to process image: {}", op.source)) - }) - .fold(|| Ok(()), Result::and) - .reduce(|| Ok(()), Result::and) + }).collect::>() } } diff --git a/components/site/src/lib.rs b/components/site/src/lib.rs index 6ce1a4f0..e5ef8064 100644 --- a/components/site/src/lib.rs +++ b/components/site/src/lib.rs @@ -272,13 +272,11 @@ impl Site { let insert_anchor = pages_insert_anchors[&page.file.path]; page.render_markdown(permalinks, tera, config, base_path, insert_anchor) }) - .fold(|| Ok(()), Result::and) - .reduce(|| Ok(()), Result::and)?; + .collect::>()?; self.sections.par_iter_mut() .map(|(_, section)| section.render_markdown(permalinks, tera, config, base_path)) - .fold(|| Ok(()), Result::and) - .reduce(|| Ok(()), Result::and)?; + .collect::>()?; Ok(()) } @@ -717,8 +715,7 @@ impl Site { ) } }) - .fold(|| Ok(()), Result::and) - .reduce(|| Ok(()), Result::and) + .collect::>() } /// What it says on the tin @@ -847,8 +844,7 @@ impl Site { .pages .par_iter() .map(|p| self.render_page(p)) - .fold(|| Ok(()), Result::and) - .reduce(|| Ok(()), Result::and)?; + .collect::>()?; } if !section.meta.render { @@ -886,8 +882,7 @@ impl Site { .collect::>() .into_par_iter() .map(|s| self.render_section(s, true)) - .fold(|| Ok(()), Result::and) - .reduce(|| Ok(()), Result::and) + .collect::>() } /// Renders all pages that do not belong to any sections @@ -924,7 +919,6 @@ impl Site { } Ok(()) }) - .fold(|| Ok(()), Result::and) - .reduce(|| Ok(()), Result::and) + .collect::>() } }