jam_types/
utils.rs

1
2
3
4
5
6
7
8
9
10
11
pub trait TakeWhen<T> {
	fn take_when(&mut self, f: impl FnOnce(&T) -> bool) -> Option<T>;
}
impl<T> TakeWhen<T> for Option<T> {
	fn take_when(&mut self, f: impl FnOnce(&T) -> bool) -> Option<T> {
		match &self {
			Some(x) if f(x) => self.take(),
			_ => None,
		}
	}
}