Skip to content

Commit 7a5da01

Browse files
authored
Merge pull request #316 from bluss/remove-flatten
Remove .flatten() and flatten()
2 parents d866c61 + 1e18077 commit 7a5da01

File tree

5 files changed

+0
-144
lines changed

5 files changed

+0
-144
lines changed

src/adaptors/mod.rs

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use std::mem::replace;
1313
use std::iter::{Fuse, Peekable, FromIterator};
1414
use std::marker::PhantomData;
1515
use size_hint;
16-
use fold;
1716

1817
macro_rules! clone_fields {
1918
($name:ident, $base:expr, $($field:ident),+) => (
@@ -1035,81 +1034,6 @@ impl_tuple_combination!(Tuple3Combination Tuple2Combination ; A, A, A, A ; a b);
10351034
impl_tuple_combination!(Tuple4Combination Tuple3Combination ; A, A, A, A, A; a b c);
10361035

10371036

1038-
/// An iterator adapter to simply flatten a structure.
1039-
///
1040-
/// See [`.flatten()`](../trait.Itertools.html#method.flatten) for more information.
1041-
#[derive(Clone, Debug)]
1042-
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
1043-
pub struct Flatten<I, J> {
1044-
iter: I,
1045-
front: Option<J>,
1046-
}
1047-
1048-
/// Flatten an iterable of iterables into a single combined sequence of all
1049-
/// the elements in the iterables.
1050-
///
1051-
/// This is more or less equivalent to `.flat_map` with an identity
1052-
/// function.
1053-
///
1054-
/// This is an `IntoIterator`-enabled version of the [`.flatten()`][1] adaptor.
1055-
///
1056-
/// [1]: trait.Itertools.html#method.flatten
1057-
///
1058-
/// ```
1059-
/// use itertools::flatten;
1060-
///
1061-
/// let data = vec![vec![1, 2, 3], vec![4, 5, 6]];
1062-
///
1063-
/// itertools::assert_equal(flatten(&data),
1064-
/// &[1, 2, 3, 4, 5, 6]);
1065-
/// ```
1066-
pub fn flatten<I, J>(iterable: I) -> Flatten<I::IntoIter, J>
1067-
where I: IntoIterator,
1068-
I::Item: IntoIterator<IntoIter=J, Item=J::Item>,
1069-
J: Iterator,
1070-
{
1071-
Flatten {
1072-
iter: iterable.into_iter(),
1073-
front: None,
1074-
}
1075-
}
1076-
1077-
impl<I, J> Iterator for Flatten<I, J>
1078-
where I: Iterator,
1079-
I::Item: IntoIterator<IntoIter=J, Item=J::Item>,
1080-
J: Iterator,
1081-
{
1082-
type Item = J::Item;
1083-
fn next(&mut self) -> Option<Self::Item> {
1084-
loop {
1085-
if let Some(ref mut f) = self.front {
1086-
match f.next() {
1087-
elt @ Some(_) => return elt,
1088-
None => { }
1089-
}
1090-
}
1091-
if let Some(next_front) = self.iter.next() {
1092-
self.front = Some(next_front.into_iter());
1093-
} else {
1094-
break;
1095-
}
1096-
}
1097-
None
1098-
}
1099-
1100-
// special case to convert segmented iterator into consecutive loops
1101-
fn fold<Acc, G>(self, init: Acc, mut f: G) -> Acc
1102-
where G: FnMut(Acc, Self::Item) -> Acc,
1103-
{
1104-
let mut accum = init;
1105-
if let Some(iter) = self.front {
1106-
accum = fold(iter, accum, &mut f);
1107-
}
1108-
self.iter.fold(accum, move |accum, iter| fold(iter, accum, &mut f))
1109-
}
1110-
1111-
}
1112-
11131037
/// An iterator adapter to apply a transformation within a nested `Result`.
11141038
///
11151039
/// See [`.map_results()`](../trait.Itertools.html#method.map_results) for more information.

src/lib.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ pub mod structs {
6969
WhileSome,
7070
Coalesce,
7171
TupleCombinations,
72-
Flatten,
7372
Positions,
7473
Update,
7574
};
@@ -107,7 +106,6 @@ pub mod structs {
107106
pub use ziptuple::Zip;
108107
}
109108
pub use structs::*;
110-
pub use adaptors::flatten;
111109
pub use concat_impl::concat;
112110
pub use cons_tuples_impl::cons_tuples;
113111
pub use diff::diff_with;
@@ -1108,29 +1106,6 @@ pub trait Itertools : Iterator {
11081106
pad_tail::pad_using(self, min, f)
11091107
}
11101108

1111-
/// Flatten an iterator of iterables into a single combined sequence of all
1112-
/// the elements in the iterables.
1113-
///
1114-
/// This is more or less equivalent to `.flat_map` with an identity
1115-
/// function.
1116-
///
1117-
/// See also the [`flatten`](fn.flatten.html) function.
1118-
///
1119-
/// ```ignore
1120-
/// use itertools::Itertools;
1121-
///
1122-
/// let data = vec![vec![1, 2, 3], vec![4, 5, 6]];
1123-
/// let flattened = data.iter().flatten();
1124-
///
1125-
/// itertools::assert_equal(flattened, &[1, 2, 3, 4, 5, 6]);
1126-
/// ```
1127-
fn flatten(self) -> Flatten<Self, <Self::Item as IntoIterator>::IntoIter>
1128-
where Self: Sized,
1129-
Self::Item: IntoIterator
1130-
{
1131-
adaptors::flatten(self)
1132-
}
1133-
11341109
/// Return an iterator adaptor that wraps each element in a `Position` to
11351110
/// ease special-case handling of the first or last elements.
11361111
///

tests/quick.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use itertools::{
1818
multizip,
1919
EitherOrBoth,
2020
};
21-
use itertools::flatten;
2221
use itertools::free::{
2322
cloned,
2423
enumerate,
@@ -607,16 +606,6 @@ quickcheck! {
607606
true
608607
}
609608

610-
fn equal_flatten(a: Vec<Option<i32>>) -> bool {
611-
itertools::equal(flatten(&a),
612-
a.iter().filter_map(|x| x.as_ref()))
613-
}
614-
615-
fn equal_flatten_vec(a: Vec<Vec<u8>>) -> bool {
616-
itertools::equal(flatten(&a),
617-
a.iter().flat_map(|x| x))
618-
}
619-
620609
fn equal_combinations_2(a: Vec<u8>) -> bool {
621610
let mut v = Vec::new();
622611
for (i, x) in enumerate(&a) {

tests/test_core.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
use core::iter;
1111

12-
use it::flatten;
1312
use it::Itertools;
1413
use it::interleave;
1514
use it::multizip;
@@ -236,19 +235,6 @@ fn part() {
236235
assert_eq!(data, [9, 6, 3, 4, 5, 2, 7, 8, 1]);
237236
}
238237

239-
#[test]
240-
fn flatten_clone() {
241-
let data = &[
242-
&[1,2,3],
243-
&[4,5,6]
244-
];
245-
let flattened1 = flatten(data.into_iter().cloned());
246-
let flattened2 = flattened1.clone();
247-
248-
it::assert_equal(flattened1, &[1,2,3,4,5,6]);
249-
it::assert_equal(flattened2, &[1,2,3,4,5,6]);
250-
}
251-
252238
#[test]
253239
fn tree_fold1() {
254240
for i in 0..100 {

tests/test_std.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#[macro_use] extern crate itertools as it;
33
extern crate permutohedron;
44

5-
use it::flatten;
65
use it::Itertools;
76
use it::multizip;
87
use it::multipeek;
@@ -538,23 +537,6 @@ fn concat_non_empty() {
538537
assert_eq!(data.into_iter().concat(), vec![1,2,3,4,5,6,7,8,9])
539538
}
540539

541-
#[test]
542-
fn flatten_iter() {
543-
let data = vec![vec![1,2,3], vec![4,5], vec![], vec![6]];
544-
it::assert_equal(flatten(data), vec![1,2,3,4,5,6]);
545-
}
546-
547-
#[test]
548-
fn flatten_fold() {
549-
let xs = [0, 1, 1, 1, 2, 1, 3, 3];
550-
let ch = xs.iter().chunks(3);
551-
let mut iter = flatten(&ch);
552-
iter.next();
553-
let mut xs_d = Vec::new();
554-
iter.fold((), |(), &elt| xs_d.push(elt));
555-
assert_eq!(&xs_d[..], &xs[1..]);
556-
}
557-
558540
#[test]
559541
fn combinations() {
560542
assert!((1..3).combinations(5).next().is_none());

0 commit comments

Comments
 (0)