feat: add catalog.for_each to inspect all items iteratively

This commit is contained in:
2025-11-11 14:32:31 +01:00
parent 20078034c5
commit 23a6ccf8fc
2 changed files with 17 additions and 0 deletions

View 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)))
})
}
}

View File

@@ -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;