Move `accumulate_result_with` helper function into `prunable` submodule
Co-authored-by: Kris Nuttycombe <kris@nutty.land>
This commit is contained in:
parent
4152961f77
commit
46592bf466
|
@ -1475,24 +1475,6 @@ impl<
|
|||
}
|
||||
}
|
||||
|
||||
// We need an applicative functor for Result for this function so that we can correctly
|
||||
// accumulate errors, but we don't have one so we just write a special- cased version here.
|
||||
fn accumulate_result_with<A, B, C>(
|
||||
left: Result<A, Vec<Address>>,
|
||||
right: Result<B, Vec<Address>>,
|
||||
combine_success: impl FnOnce(A, B) -> C,
|
||||
) -> Result<C, Vec<Address>> {
|
||||
match (left, right) {
|
||||
(Ok(a), Ok(b)) => Ok(combine_success(a, b)),
|
||||
(Err(mut xs), Err(mut ys)) => {
|
||||
xs.append(&mut ys);
|
||||
Err(xs)
|
||||
}
|
||||
(Ok(_), Err(xs)) => Err(xs),
|
||||
(Err(xs), Ok(_)) => Err(xs),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use assert_matches::assert_matches;
|
||||
|
|
|
@ -8,7 +8,7 @@ use incrementalmerkletree::{
|
|||
frontier::NonEmptyFrontier, Address, Hashable, Level, Position, Retention,
|
||||
};
|
||||
|
||||
use crate::{accumulate_result_with, LocatedTree, Node, Tree};
|
||||
use crate::{LocatedTree, Node, Tree};
|
||||
|
||||
#[cfg(feature = "legacy-api")]
|
||||
use incrementalmerkletree::witness::IncrementalWitness;
|
||||
|
@ -1396,6 +1396,24 @@ impl<H: Hashable + Clone + PartialEq> LocatedPrunableTree<H> {
|
|||
}
|
||||
}
|
||||
|
||||
// We need an applicative functor for Result for this function so that we can correctly
|
||||
// accumulate errors, but we don't have one so we just write a special- cased version here.
|
||||
fn accumulate_result_with<A, B, C>(
|
||||
left: Result<A, Vec<Address>>,
|
||||
right: Result<B, Vec<Address>>,
|
||||
combine_success: impl FnOnce(A, B) -> C,
|
||||
) -> Result<C, Vec<Address>> {
|
||||
match (left, right) {
|
||||
(Ok(a), Ok(b)) => Ok(combine_success(a, b)),
|
||||
(Err(mut xs), Err(mut ys)) => {
|
||||
xs.append(&mut ys);
|
||||
Err(xs)
|
||||
}
|
||||
(Ok(_), Err(xs)) => Err(xs),
|
||||
(Err(xs), Ok(_)) => Err(xs),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::collections::BTreeSet;
|
||||
|
|
Loading…
Reference in New Issue