Skip to repository content43 lines · 896 B · rust
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T02:57:16.762Z Public web read
NIP-34 coordinate
30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omegaMaintainersHidden in public view
References2 branches · 1 tag
Read-only clone
git clone https://openagents.com/git/tenant.openagents/omega.gitBrowse files
utils.rs
1pub(crate) struct ReversibleIterable<It> {
2 pub(crate) it: It,
3 pub(crate) reverse: bool,
4}
5
6impl<T> ReversibleIterable<T> {
7 pub(crate) fn new(it: T, reverse: bool) -> Self {
8 Self { it, reverse }
9 }
10}
11
12impl<It, Item> ReversibleIterable<It>
13where
14 It: Iterator<Item = Item>,
15{
16 pub(crate) fn find_single_ended<F>(mut self, pred: F) -> Option<Item>
17 where
18 F: FnMut(&Item) -> bool,
19 {
20 if self.reverse {
21 self.it.filter(pred).last()
22 } else {
23 self.it.find(pred)
24 }
25 }
26}
27
28impl<It, Item> ReversibleIterable<It>
29where
30 It: DoubleEndedIterator<Item = Item>,
31{
32 pub(crate) fn find<F>(mut self, mut pred: F) -> Option<Item>
33 where
34 F: FnMut(&Item) -> bool,
35 {
36 if self.reverse {
37 self.it.rfind(|x| pred(x))
38 } else {
39 self.it.find(|x| pred(x))
40 }
41 }
42}
43