added a find function to model

This commit is contained in:
Chris Cochrun 2024-10-09 15:47:53 -05:00
parent 125289ace1
commit 3e1e46ce2b
5 changed files with 16 additions and 11 deletions

View file

@ -36,11 +36,16 @@ impl<T> Model<T> {
Ok(())
}
pub fn get_item<P>(&self, f: P) -> Option<&T>
pub fn get_item(&self, index: i32) -> Option<&T>
{
self.items.get(index as usize)
}
pub fn find<P>(&self, f: P) -> Option<&T>
where
P: FnMut(&&T) -> bool,
{
self.items.iter().filter(f).next()
self.items.iter().find(f)
}
pub fn insert_item(&mut self, item: T, index: i32) -> Result<()> {