aoc_framework_utils/acting_closures/mod.rs
1/// Trait for closures acting on a generic type
2pub trait ActingClosures<T, U> {
3 /// returns a new value returned by the closure
4 fn apply<F>(self, closure: F) -> U where F: Fn(T) -> U;
5 /// returns the value on which the closure is applied
6 fn also<F>(self, closure: F) -> T where F: Fn(&T);
7}
8
9impl <T, U> ActingClosures<T, U> for T {
10 fn apply<F>(self, closure: F) -> U where F: Fn(T) -> U {
11 closure(self)
12 }
13
14 fn also<F>(self, closure: F) -> T where F: Fn(&T) {
15 closure(&self);
16 self
17 }
18}