|
5 | 5 | //! except according to those terms.
|
6 | 6 |
|
7 | 7 | mod coalesce;
|
| 8 | +mod map; |
8 | 9 | mod multi_product;
|
9 | 10 | pub use self::coalesce::*;
|
| 11 | +pub use self::map::{map_into, map_ok, MapInto, MapOk}; |
| 12 | +#[allow(deprecated)] |
| 13 | +pub use self::map::MapResults; |
10 | 14 | #[cfg(feature = "use_std")]
|
11 | 15 | pub use self::multi_product::*;
|
12 | 16 |
|
@@ -806,118 +810,6 @@ impl_tuple_combination!(Tuple2Combination Tuple1Combination ; A, A, A ; a);
|
806 | 810 | impl_tuple_combination!(Tuple3Combination Tuple2Combination ; A, A, A, A ; a b);
|
807 | 811 | impl_tuple_combination!(Tuple4Combination Tuple3Combination ; A, A, A, A, A; a b c);
|
808 | 812 |
|
809 |
| -/// An iterator adapter to apply `Into` conversion to each element. |
810 |
| -/// |
811 |
| -/// See [`.map_into()`](../trait.Itertools.html#method.map_into) for more information. |
812 |
| -#[derive(Clone)] |
813 |
| -#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] |
814 |
| -pub struct MapInto<I, R> { |
815 |
| - iter: I, |
816 |
| - _res: PhantomData<R>, |
817 |
| -} |
818 |
| - |
819 |
| -/// Create a new [`MapInto`](struct.MapInto.html) iterator. |
820 |
| -pub fn map_into<I, R>(iter: I) -> MapInto<I, R> { |
821 |
| - MapInto { |
822 |
| - iter, |
823 |
| - _res: PhantomData, |
824 |
| - } |
825 |
| -} |
826 |
| - |
827 |
| -impl<I, R> Iterator for MapInto<I, R> |
828 |
| - where I: Iterator, |
829 |
| - I::Item: Into<R>, |
830 |
| -{ |
831 |
| - type Item = R; |
832 |
| - |
833 |
| - fn next(&mut self) -> Option<Self::Item> { |
834 |
| - self.iter |
835 |
| - .next() |
836 |
| - .map(|i| i.into()) |
837 |
| - } |
838 |
| - |
839 |
| - fn size_hint(&self) -> (usize, Option<usize>) { |
840 |
| - self.iter.size_hint() |
841 |
| - } |
842 |
| - |
843 |
| - fn fold<Acc, Fold>(self, init: Acc, mut fold_f: Fold) -> Acc |
844 |
| - where Fold: FnMut(Acc, Self::Item) -> Acc, |
845 |
| - { |
846 |
| - self.iter.fold(init, move |acc, v| fold_f(acc, v.into())) |
847 |
| - } |
848 |
| -} |
849 |
| - |
850 |
| -impl<I, R> DoubleEndedIterator for MapInto<I, R> |
851 |
| - where I: DoubleEndedIterator, |
852 |
| - I::Item: Into<R>, |
853 |
| -{ |
854 |
| - fn next_back(&mut self) -> Option<Self::Item> { |
855 |
| - self.iter |
856 |
| - .next_back() |
857 |
| - .map(|i| i.into()) |
858 |
| - } |
859 |
| -} |
860 |
| - |
861 |
| -impl<I, R> ExactSizeIterator for MapInto<I, R> |
862 |
| -where |
863 |
| - I: ExactSizeIterator, |
864 |
| - I::Item: Into<R>, |
865 |
| -{} |
866 |
| - |
867 |
| -/// See [`MapOk`](struct.MapOk.html). |
868 |
| -#[deprecated(note="Use MapOk instead", since="0.10")] |
869 |
| -pub type MapResults<I, F> = MapOk<I, F>; |
870 |
| - |
871 |
| -/// An iterator adapter to apply a transformation within a nested `Result::Ok`. |
872 |
| -/// |
873 |
| -/// See [`.map_ok()`](../trait.Itertools.html#method.map_ok) for more information. |
874 |
| -#[derive(Clone)] |
875 |
| -#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] |
876 |
| -pub struct MapOk<I, F> { |
877 |
| - iter: I, |
878 |
| - f: F |
879 |
| -} |
880 |
| - |
881 |
| -/// Create a new `MapOk` iterator. |
882 |
| -pub fn map_ok<I, F, T, U, E>(iter: I, f: F) -> MapOk<I, F> |
883 |
| - where I: Iterator<Item = Result<T, E>>, |
884 |
| - F: FnMut(T) -> U, |
885 |
| -{ |
886 |
| - MapOk { |
887 |
| - iter, |
888 |
| - f, |
889 |
| - } |
890 |
| -} |
891 |
| - |
892 |
| -impl<I, F, T, U, E> Iterator for MapOk<I, F> |
893 |
| - where I: Iterator<Item = Result<T, E>>, |
894 |
| - F: FnMut(T) -> U, |
895 |
| -{ |
896 |
| - type Item = Result<U, E>; |
897 |
| - |
898 |
| - fn next(&mut self) -> Option<Self::Item> { |
899 |
| - self.iter.next().map(|v| v.map(&mut self.f)) |
900 |
| - } |
901 |
| - |
902 |
| - fn size_hint(&self) -> (usize, Option<usize>) { |
903 |
| - self.iter.size_hint() |
904 |
| - } |
905 |
| - |
906 |
| - fn fold<Acc, Fold>(self, init: Acc, mut fold_f: Fold) -> Acc |
907 |
| - where Fold: FnMut(Acc, Self::Item) -> Acc, |
908 |
| - { |
909 |
| - let mut f = self.f; |
910 |
| - self.iter.fold(init, move |acc, v| fold_f(acc, v.map(&mut f))) |
911 |
| - } |
912 |
| - |
913 |
| - fn collect<C>(self) -> C |
914 |
| - where C: FromIterator<Self::Item> |
915 |
| - { |
916 |
| - let mut f = self.f; |
917 |
| - self.iter.map(move |v| v.map(&mut f)).collect() |
918 |
| - } |
919 |
| -} |
920 |
| - |
921 | 813 | /// An iterator adapter to filter values within a nested `Result::Ok`.
|
922 | 814 | ///
|
923 | 815 | /// See [`.filter_ok()`](../trait.Itertools.html#method.filter_ok) for more information.
|
|
0 commit comments