I’ve the following code, which I am trying to simplify by writing my own `min_or_max()`

method:

```
if depth % 2 == 0 {
children.iter()
.map(|child| TreeNode::score_depth(child, depth + 1))
.max()
.unwrap()
} else {
children.iter()
.map(|child| TreeNode::score_depth(child, depth + 1))
.min()
.unwrap()
}
```

`children`

is a `Vec<TreeNode>`

and I’ve attempted to implement a custom trait for `Iterator`

:

```
trait MinMax {
type Item;
fn min_or_max(self, max: bool) -> Option<Self::Item> where Self: Sized, Self::Item: Ord;
}
impl MinMax for Iterator {
type Item = Self;
fn min_or_max(self, max: bool) -> Option<Self::Item> where Self: Sized, Self::Item: Ord {
if max {
self.max()
} else {
self.min()
}
}
}
```

However, I can’t work out what I actually need to implement this trait on or what the correct method signature should be. Could someone please point me in the right direction?