feat: add catalog.for_each to inspect all items iteratively
This commit is contained in:
16
01.workspace/heave/src/imp/catalog_for_each.rs
Normal file
16
01.workspace/heave/src/imp/catalog_for_each.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
use crate::*;
|
||||
|
||||
impl Catalog {
|
||||
pub fn for_each<T, F>(&self, predicate: F) -> Result<(), FailedTo>
|
||||
where
|
||||
T: EAV,
|
||||
F: Fn(&T) -> (),
|
||||
{
|
||||
self.with_items(|items| {
|
||||
Ok(items
|
||||
.values()
|
||||
.flat_map(|entity| T::try_from(entity.clone()).map_err(|_| FailedTo::ConvertEntity))
|
||||
.for_each(|item| predicate(&item)))
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
pub mod bool_try_from_value;
|
||||
pub mod catalog_contains_key;
|
||||
pub mod catalog_delete;
|
||||
pub mod catalog_for_each;
|
||||
pub mod catalog_get;
|
||||
pub mod catalog_get_by;
|
||||
pub mod catalog_init;
|
||||
|
||||
Reference in New Issue
Block a user