Skip to content

Commit

Permalink
Implement FlattenOk::rfold
Browse files Browse the repository at this point in the history
  • Loading branch information
kinto-b committed May 1, 2024
1 parent bb31180 commit fc5aab4
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/flatten_ok.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,29 @@ where
}
}
}

fn rfold<B, F>(self, init: B, mut f: F) -> B
where
Self: Sized,
F: FnMut(B, Self::Item) -> B,
{
// Back
let mut acc = match self.inner_back {
Some(x) => x.rfold(init, |a, o| f(a, Ok(o))),
None => init,
};

acc = self.iter.rfold(acc, |acc, x| match x {
Ok(it) => it.into_iter().rfold(acc, |a, o| f(a, Ok(o))),
Err(e) => f(acc, Err(e)),
});

// Front
match self.inner_front {
Some(x) => x.rfold(acc, |a, o| f(a, Ok(o))),
None => acc,
}
}
}

impl<I, T, E> Clone for FlattenOk<I, T, E>
Expand Down

0 comments on commit fc5aab4

Please sign in to comment.