David Tolnay | f60f426 | 2017-12-28 19:17:58 -0500 | [diff] [blame^] | 1 | #[cfg(feature = "fold")] |
| 2 | pub mod fold { |
| 3 | use delimited::Delimited; |
| 4 | |
| 5 | pub trait FoldHelper { |
| 6 | type Item; |
| 7 | fn lift<F>(self, f: F) -> Self where F: FnMut(Self::Item) -> Self::Item; |
| 8 | } |
| 9 | |
| 10 | impl<T> FoldHelper for Vec<T> { |
| 11 | type Item = T; |
| 12 | fn lift<F>(self, f: F) -> Self where F: FnMut(Self::Item) -> Self::Item { |
| 13 | self.into_iter().map(f).collect() |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | impl<T, U> FoldHelper for Delimited<T, U> { |
| 18 | type Item = T; |
| 19 | fn lift<F>(self, mut f: F) -> Self where F: FnMut(Self::Item) -> Self::Item { |
| 20 | self.into_iter().map(|elem| { |
| 21 | let (t, u) = elem.into_tuple(); |
| 22 | (f(t), u) |
| 23 | }).collect::<Vec<(T, Option<U>)>>().into() |
| 24 | } |
| 25 | } |
| 26 | } |