Skip to content

Commit 3890a93

Browse files
committed
Rename .*_results() -> .*_ok()
1 parent 20abbbc commit 3890a93

File tree

2 files changed

+56
-37
lines changed

2 files changed

+56
-37
lines changed

src/adaptors/mod.rs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,28 +1074,31 @@ where
10741074
I::Item: Into<R>,
10751075
{}
10761076

1077-
/// An iterator adapter to apply a transformation within a nested `Result`.
1077+
#[deprecated(note="Use MapOk instead", since="0.10")]
1078+
pub type MapResults<I, F> = MapOk<I, F>;
1079+
1080+
/// An iterator adapter to apply a transformation within a nested `Result::Ok`.
10781081
///
1079-
/// See [`.map_results()`](../trait.Itertools.html#method.map_results) for more information.
1082+
/// See [`.map_ok()`](../trait.Itertools.html#method.map_ok) for more information.
10801083
#[derive(Clone)]
10811084
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
1082-
pub struct MapResults<I, F> {
1085+
pub struct MapOk<I, F> {
10831086
iter: I,
10841087
f: F
10851088
}
10861089

1087-
/// Create a new `MapResults` iterator.
1088-
pub fn map_results<I, F, T, U, E>(iter: I, f: F) -> MapResults<I, F>
1090+
/// Create a new `MapOk` iterator.
1091+
pub fn map_ok<I, F, T, U, E>(iter: I, f: F) -> MapOk<I, F>
10891092
where I: Iterator<Item = Result<T, E>>,
10901093
F: FnMut(T) -> U,
10911094
{
1092-
MapResults {
1095+
MapOk {
10931096
iter,
10941097
f,
10951098
}
10961099
}
10971100

1098-
impl<I, F, T, U, E> Iterator for MapResults<I, F>
1101+
impl<I, F, T, U, E> Iterator for MapOk<I, F>
10991102
where I: Iterator<Item = Result<T, E>>,
11001103
F: FnMut(T) -> U,
11011104
{
@@ -1124,28 +1127,28 @@ impl<I, F, T, U, E> Iterator for MapResults<I, F>
11241127
}
11251128
}
11261129

1127-
/// An iterator adapter to filter values within a nested `Result`.
1130+
/// An iterator adapter to filter values within a nested `Result::Ok`.
11281131
///
1129-
/// See [`.filter_results()`](../trait.Itertools.html#method.filter_results) for more information.
1132+
/// See [`.filter_ok()`](../trait.Itertools.html#method.filter_ok) for more information.
11301133
#[derive(Clone)]
11311134
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
1132-
pub struct FilterResults<I, F> {
1135+
pub struct FilterOk<I, F> {
11331136
iter: I,
11341137
f: F
11351138
}
11361139

1137-
/// Create a new `FilterResults` iterator.
1138-
pub fn filter_results<I, F, T, E>(iter: I, f: F) -> FilterResults<I, F>
1140+
/// Create a new `FilterOk` iterator.
1141+
pub fn filter_ok<I, F, T, E>(iter: I, f: F) -> FilterOk<I, F>
11391142
where I: Iterator<Item = Result<T, E>>,
11401143
F: FnMut(&T) -> bool,
11411144
{
1142-
FilterResults {
1145+
FilterOk {
11431146
iter,
11441147
f,
11451148
}
11461149
}
11471150

1148-
impl<I, F, T, E> Iterator for FilterResults<I, F>
1151+
impl<I, F, T, E> Iterator for FilterOk<I, F>
11491152
where I: Iterator<Item = Result<T, E>>,
11501153
F: FnMut(&T) -> bool,
11511154
{
@@ -1188,12 +1191,11 @@ impl<I, F, T, E> Iterator for FilterResults<I, F>
11881191
}
11891192
}
11901193

1191-
/// An iterator adapter to filter and apply a transformation on values within a nested `Result`.
1194+
/// An iterator adapter to filter and apply a transformation on values within a nested `Result::Ok`.
11921195
///
1193-
/// See [`.filter_map_results()`](../trait.Itertools.html#method.filter_map_results) for more information.
1194-
#[derive(Clone)]
1196+
/// See [`.filter_map_ok()`](../trait.Itertools.html#method.filter_map_ok) for more information.
11951197
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
1196-
pub struct FilterMapResults<I, F> {
1198+
pub struct FilterMapOk<I, F> {
11971199
iter: I,
11981200
f: F
11991201
}
@@ -1206,18 +1208,18 @@ fn transpose_result<T, E>(result: Result<Option<T>, E>) -> Option<Result<T, E>>
12061208
}
12071209
}
12081210

1209-
/// Create a new `FilterResults` iterator.
1210-
pub fn filter_map_results<I, F, T, U, E>(iter: I, f: F) -> FilterMapResults<I, F>
1211+
/// Create a new `FilterOk` iterator.
1212+
pub fn filter_map_ok<I, F, T, U, E>(iter: I, f: F) -> FilterMapOk<I, F>
12111213
where I: Iterator<Item = Result<T, E>>,
12121214
F: FnMut(T) -> Option<U>,
12131215
{
1214-
FilterMapResults {
1216+
FilterMapOk {
12151217
iter,
12161218
f,
12171219
}
12181220
}
12191221

1220-
impl<I, F, T, U, E> Iterator for FilterMapResults<I, F>
1222+
impl<I, F, T, U, E> Iterator for FilterMapOk<I, F>
12211223
where I: Iterator<Item = Result<T, E>>,
12221224
F: FnMut(T) -> Option<U>,
12231225
{

src/lib.rs

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,13 @@ pub mod structs {
8080
DedupBy,
8181
Interleave,
8282
InterleaveShortest,
83-
FilterMapResults,
84-
FilterResults,
83+
FilterMapOk,
84+
FilterOk,
8585
Product,
8686
PutBack,
8787
Batching,
8888
MapInto,
89+
MapOk,
8990
MapResults,
9091
Merge,
9192
MergeBy,
@@ -721,6 +722,14 @@ pub trait Itertools : Iterator {
721722
adaptors::map_into(self)
722723
}
723724

725+
#[deprecated(note="Use .map_ok() instead", since="0.10")]
726+
fn map_results<F, T, U, E>(self, f: F) -> MapOk<Self, F>
727+
where Self: Iterator<Item = Result<T, E>> + Sized,
728+
F: FnMut(T) -> U,
729+
{
730+
self.map_ok(f)
731+
}
732+
724733
/// Return an iterator adaptor that applies the provided closure
725734
/// to every `Result::Ok` value. `Result::Err` values are
726735
/// unchanged.
@@ -729,14 +738,14 @@ pub trait Itertools : Iterator {
729738
/// use itertools::Itertools;
730739
///
731740
/// let input = vec![Ok(41), Err(false), Ok(11)];
732-
/// let it = input.into_iter().map_results(|i| i + 1);
741+
/// let it = input.into_iter().map_ok(|i| i + 1);
733742
/// itertools::assert_equal(it, vec![Ok(42), Err(false), Ok(12)]);
734743
/// ```
735-
fn map_results<F, T, U, E>(self, f: F) -> MapResults<Self, F>
744+
fn map_ok<F, T, U, E>(self, f: F) -> MapOk<Self, F>
736745
where Self: Iterator<Item = Result<T, E>> + Sized,
737746
F: FnMut(T) -> U,
738747
{
739-
adaptors::map_results(self, f)
748+
adaptors::map_ok(self, f)
740749
}
741750

742751
/// Return an iterator adaptor that filters every `Result::Ok`
@@ -747,14 +756,14 @@ pub trait Itertools : Iterator {
747756
/// use itertools::Itertools;
748757
///
749758
/// let input = vec![Ok(22), Err(false), Ok(11)];
750-
/// let it = input.into_iter().filter_results(|&i| i > 20);
759+
/// let it = input.into_iter().filter_ok(|&i| i > 20);
751760
/// itertools::assert_equal(it, vec![Ok(22), Err(false)]);
752761
/// ```
753-
fn filter_results<F, T, E>(self, f: F) -> FilterResults<Self, F>
762+
fn filter_ok<F, T, E>(self, f: F) -> FilterOk<Self, F>
754763
where Self: Iterator<Item = Result<T, E>> + Sized,
755764
F: FnMut(&T) -> bool,
756765
{
757-
adaptors::filter_results(self, f)
766+
adaptors::filter_ok(self, f)
758767
}
759768

760769
/// Return an iterator adaptor that filters and transforms every
@@ -765,14 +774,14 @@ pub trait Itertools : Iterator {
765774
/// use itertools::Itertools;
766775
///
767776
/// let input = vec![Ok(22), Err(false), Ok(11)];
768-
/// let it = input.into_iter().filter_map_results(|i| if i > 20 { Some(i * 2) } else { None });
777+
/// let it = input.into_iter().filter_map_ok(|i| if i > 20 { Some(i * 2) } else { None });
769778
/// itertools::assert_equal(it, vec![Ok(44), Err(false)]);
770779
/// ```
771-
fn filter_map_results<F, T, U, E>(self, f: F) -> FilterMapResults<Self, F>
780+
fn filter_map_ok<F, T, U, E>(self, f: F) -> FilterMapOk<Self, F>
772781
where Self: Iterator<Item = Result<T, E>> + Sized,
773782
F: FnMut(T) -> Option<U>,
774783
{
775-
adaptors::filter_map_results(self, f)
784+
adaptors::filter_map_ok(self, f)
776785
}
777786

778787
/// Return an iterator adaptor that merges the two base iterators in
@@ -1761,6 +1770,14 @@ pub trait Itertools : Iterator {
17611770
format::new_format(self, sep, format)
17621771
}
17631772

1773+
#[deprecated(note="Use .fold_ok() instead", since="0.10")]
1774+
fn fold_results<A, E, B, F>(&mut self, mut start: B, mut f: F) -> Result<B, E>
1775+
where Self: Iterator<Item = Result<A, E>>,
1776+
F: FnMut(B, A) -> B
1777+
{
1778+
self.fold_ok(start, f)
1779+
}
1780+
17641781
/// Fold `Result` values from an iterator.
17651782
///
17661783
/// Only `Ok` values are folded. If no error is encountered, the folded
@@ -1793,17 +1810,17 @@ pub trait Itertools : Iterator {
17931810
/// assert_eq!(
17941811
/// values.iter()
17951812
/// .map(Ok::<_, ()>)
1796-
/// .fold_results(0, Add::add),
1813+
/// .fold_ok(0, Add::add),
17971814
/// Ok(3)
17981815
/// );
17991816
/// assert!(
18001817
/// values.iter()
18011818
/// .map(|&x| if x >= 0 { Ok(x) } else { Err("Negative number") })
1802-
/// .fold_results(0, Add::add)
1819+
/// .fold_ok(0, Add::add)
18031820
/// .is_err()
18041821
/// );
18051822
/// ```
1806-
fn fold_results<A, E, B, F>(&mut self, mut start: B, mut f: F) -> Result<B, E>
1823+
fn fold_ok<A, E, B, F>(&mut self, mut start: B, mut f: F) -> Result<B, E>
18071824
where Self: Iterator<Item = Result<A, E>>,
18081825
F: FnMut(B, A) -> B
18091826
{
@@ -1822,7 +1839,7 @@ pub trait Itertools : Iterator {
18221839
/// value is returned inside `Some`. Otherwise, the operation terminates
18231840
/// and returns `None`. No iterator elements are consumed after the `None`.
18241841
///
1825-
/// This is the `Option` equivalent to `fold_results`.
1842+
/// This is the `Option` equivalent to `fold_ok`.
18261843
///
18271844
/// ```
18281845
/// use std::ops::Add;

0 commit comments

Comments
 (0)