1use super::*;
2
3pub trait MapResultFn {
4 type Input;
5 type Output;
6 fn map(self, input: Self::Input) -> Self::Output;
7}
8
9pub struct MapResultList<I, E>
10where
11 I: ListFn,
12 I::End: ResultFn,
13 E: MapResultFn<Input = <I::End as ResultFn>::Result>,
14{
15 input: I,
16 map: E,
17}
18
19impl<I, E> ListFn for MapResultList<I, E>
20where
21 I: ListFn,
22 I::End: ResultFn,
23 E: MapResultFn<Input = <I::End as ResultFn>::Result>,
24{
25 type Item = I::Item;
26 type End = Id<E::Output>;
27 fn next(self) -> ListState<Self> {
28 match self.input.next() {
29 ListState::Some(some) => ListState::some(
30 some.first,
31 MapResultList {
32 input: some.next,
33 map: self.map,
34 },
35 ),
36 ListState::End(end) => ListState::End(Id::new(self.map.map(end.result()))),
37 }
38 }
39}
40
41pub trait MapResult
42where
43 Self: ListFn,
44 Self::End: ResultFn,
45{
46 fn map_result<E: MapResultFn<Input = <Self::End as ResultFn>::Result>>(
47 self,
48 map: E,
49 ) -> MapResultList<Self, E> {
50 MapResultList { input: self, map }
51 }
52}
53
54impl<T> MapResult for T
55where
56 T: ListFn,
57 T::End: ResultFn,
58{
59}