Skip to content

Commit c9af57f

Browse files
authored
Merge pull request #195 from bluss/next
Implement breaking changes for next version
2 parents 8d76712 + b3fe350 commit c9af57f

File tree

8 files changed

+55
-177
lines changed

8 files changed

+55
-177
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ language: rust
22
sudo: false
33
matrix:
44
include:
5-
- rust: 1.11.0
5+
- rust: 1.12.0
66
- rust: stable
77
- rust: beta
88
- rust: nightly

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Itertools
33
=========
44

5-
Extra iterator adaptors, functions and macros. Requires Rust 1.11 or later.
5+
Extra iterator adaptors, functions and macros.
66

77
Please read the `API documentation here`__
88

src/adaptors/mod.rs

Lines changed: 5 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,6 @@ pub fn put_back<I>(iterable: I) -> PutBack<I::IntoIter>
193193
impl<I> PutBack<I>
194194
where I: Iterator
195195
{
196-
#[doc(hidden)]
197-
#[deprecated(note = "replaced by put_back")]
198-
#[inline]
199-
pub fn new(it: I) -> Self {
200-
PutBack {
201-
top: None,
202-
iter: it,
203-
}
204-
}
205-
206196
/// put back value `value` (builder method)
207197
pub fn with_value(mut self, value: I::Item) -> Self {
208198
self.put_back(value);
@@ -288,21 +278,14 @@ pub fn put_back_n<I>(iterable: I) -> PutBackN<I::IntoIter>
288278
}
289279

290280
impl<I: Iterator> PutBackN<I> {
291-
#[doc(hidden)]
292-
#[deprecated(note = "replaced by put_back_n")]
293-
#[inline]
294-
pub fn new(it: I) -> Self {
295-
put_back_n(it)
296-
}
297-
298281
/// Puts x in front of the iterator.
299282
/// The values are yielded in order of the most recently put back
300283
/// values first.
301284
///
302285
/// ```rust
303-
/// use itertools::PutBackN;
286+
/// use itertools::put_back_n;
304287
///
305-
/// let mut it = PutBackN::new(1..5);
288+
/// let mut it = put_back_n(1..5);
306289
/// it.next();
307290
/// it.put_back(1);
308291
/// it.put_back(0);
@@ -1155,7 +1138,6 @@ impl<I> fmt::Debug for Combinations<I>
11551138
pub fn combinations<I>(iter: I, n: usize) -> Combinations<I>
11561139
where I: Iterator
11571140
{
1158-
assert!(n != 0);
11591141
let mut indices: Vec<usize> = Vec::with_capacity(n);
11601142
for i in 0..n {
11611143
indices.push(i);
@@ -1191,6 +1173,8 @@ impl<I> Iterator for Combinations<I>
11911173

11921174
if self.first {
11931175
self.first = false;
1176+
} else if self.n == 0 {
1177+
return None;
11941178
} else {
11951179
// Scan from the end, looking for an index to increment
11961180
let mut i: usize = self.n - 1;
@@ -1350,15 +1334,13 @@ pub fn unique<I>(iter: I) -> Unique<I>
13501334
pub struct Flatten<I, J> {
13511335
iter: I,
13521336
front: Option<J>,
1353-
back: Option<J>,
13541337
}
13551338

13561339
/// Create a new `Flatten` iterator.
13571340
pub fn flatten<I, J>(iter: I) -> Flatten<I, J> {
13581341
Flatten {
13591342
iter: iter,
13601343
front: None,
1361-
back: None,
13621344
}
13631345
}
13641346

@@ -1382,12 +1364,6 @@ impl<I, J> Iterator for Flatten<I, J>
13821364
break;
13831365
}
13841366
}
1385-
if let Some(ref mut b) = self.back {
1386-
match b.next() {
1387-
elt @ Some(_) => return elt,
1388-
None => { }
1389-
}
1390-
}
13911367
None
13921368
}
13931369

@@ -1399,42 +1375,7 @@ impl<I, J> Iterator for Flatten<I, J>
13991375
if let Some(iter) = self.front {
14001376
accum = fold(iter, accum, &mut f);
14011377
}
1402-
for iter in self.iter {
1403-
accum = fold(iter, accum, &mut f);
1404-
}
1405-
if let Some(iter) = self.back {
1406-
accum = fold(iter, accum, &mut f);
1407-
}
1408-
accum
1409-
}
1410-
}
1411-
1412-
impl<I, J> DoubleEndedIterator for Flatten<I, J>
1413-
where I: DoubleEndedIterator,
1414-
I::Item: IntoIterator<IntoIter=J, Item=J::Item>,
1415-
J: DoubleEndedIterator,
1416-
{
1417-
fn next_back(&mut self) -> Option<Self::Item> {
1418-
loop {
1419-
if let Some(ref mut b) = self.back {
1420-
match b.next_back() {
1421-
elt @ Some(_) => return elt,
1422-
None => { }
1423-
}
1424-
}
1425-
if let Some(next_back) = self.iter.next_back() {
1426-
self.back = Some(next_back.into_iter());
1427-
} else {
1428-
break;
1429-
}
1430-
}
1431-
if let Some(ref mut f) = self.front {
1432-
match f.next_back() {
1433-
elt @ Some(_) => return elt,
1434-
None => { }
1435-
}
1436-
}
1437-
None
1378+
self.iter.fold(accum, move |accum, iter| fold(iter, accum, &mut f))
14381379
}
14391380
}
14401381

src/lib.rs

Lines changed: 45 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,9 @@
1515
//! #[macro_use] extern crate itertools;
1616
//! ```
1717
//!
18-
//! ## License
19-
//! Dual-licensed to be compatible with the Rust project.
20-
//!
21-
//! Licensed under the Apache License, Version 2.0
22-
//! http://www.apache.org/licenses/LICENSE-2.0 or the MIT license
23-
//! http://opensource.org/licenses/MIT, at your
24-
//! option. This file may not be copied, modified, or distributed
25-
//! except according to those terms.
18+
//! ## Rust Version
2619
//!
20+
//! This version of itertools requires Rust 1.12 or later.
2721
//!
2822
#![doc(html_root_url="https://docs.rs/itertools/")]
2923

@@ -367,15 +361,6 @@ pub trait Itertools : Iterator {
367361
groupbylazy::new(self, key)
368362
}
369363

370-
///
371-
#[deprecated(note = "renamed to .group_by()")]
372-
fn group_by_lazy<K, F>(self, key: F) -> GroupBy<K, Self, F>
373-
where Self: Sized,
374-
F: FnMut(&Self::Item) -> K,
375-
{
376-
self.group_by(key)
377-
}
378-
379364
/// Return an *iterable* that can chunk the iterator.
380365
///
381366
/// Yield subiterators (chunks) that each yield a fixed number elements,
@@ -410,14 +395,6 @@ pub trait Itertools : Iterator {
410395
groupbylazy::new_chunks(self, size)
411396
}
412397

413-
///
414-
#[deprecated(note = "renamed to .chunks()")]
415-
fn chunks_lazy(self, size: usize) -> IntoChunks<Self>
416-
where Self: Sized,
417-
{
418-
self.chunks(size)
419-
}
420-
421398
/// Return an iterator over all contiguous windows producing tuples of
422399
/// a specific size (up to 4).
423400
///
@@ -621,10 +598,10 @@ pub trait Itertools : Iterator {
621598
/// let it = vec![a, b, c].into_iter().kmerge();
622599
/// itertools::assert_equal(it, vec![0, 1, 2, 3, 4, 5]);
623600
/// ```
624-
fn kmerge(self) -> KMerge<<<Self as Iterator>::Item as IntoIterator>::IntoIter>
601+
fn kmerge(self) -> KMerge<<Self::Item as IntoIterator>::IntoIter>
625602
where Self: Sized,
626603
Self::Item: IntoIterator,
627-
<<Self as Iterator>::Item as IntoIterator>::Item: PartialOrd,
604+
<Self::Item as IntoIterator>::Item: PartialOrd,
628605
{
629606
kmerge(self)
630607
}
@@ -650,11 +627,11 @@ pub trait Itertools : Iterator {
650627
/// assert_eq!(it.last(), Some(-7.));
651628
/// ```
652629
fn kmerge_by<F>(self, first: F)
653-
-> KMergeBy<<<Self as Iterator>::Item as IntoIterator>::IntoIter, F>
630+
-> KMergeBy<<Self::Item as IntoIterator>::IntoIter, F>
654631
where Self: Sized,
655632
Self::Item: IntoIterator,
656-
F: FnMut(&<<Self as Iterator>::Item as IntoIterator>::Item,
657-
&<<Self as Iterator>::Item as IntoIterator>::Item) -> bool
633+
F: FnMut(&<Self::Item as IntoIterator>::Item,
634+
&<Self::Item as IntoIterator>::Item) -> bool
658635
{
659636
kmerge_by(self, first)
660637
}
@@ -888,8 +865,6 @@ pub trait Itertools : Iterator {
888865
/// Iterator element type is `Vec<Self::Item>`. The iterator produces a new Vec per iteration,
889866
/// and clones the iterator elements.
890867
///
891-
/// **Panics** if `n` is zero.
892-
///
893868
/// ```
894869
/// use itertools::Itertools;
895870
///
@@ -934,17 +909,18 @@ pub trait Itertools : Iterator {
934909

935910
/// Unravel a nested iterator.
936911
///
937-
/// This is a shortcut for `it.flat_map(|x| x)`.
912+
/// This is more or less equivalent to `.flat_map` with an identity
913+
/// function.
938914
///
939915
/// ```
940916
/// use itertools::Itertools;
941917
///
942918
/// let data = vec![vec![1, 2, 3], vec![4, 5, 6]];
943-
/// let flattened = data.into_iter().flatten();
919+
/// let flattened = data.iter().flatten();
944920
///
945-
/// itertools::assert_equal(flattened, vec![1, 2, 3, 4, 5, 6]);
921+
/// itertools::assert_equal(flattened, &[1, 2, 3, 4, 5, 6]);
946922
/// ```
947-
fn flatten(self) -> Flatten<Self, <<Self as Iterator>::Item as IntoIterator>::IntoIter>
923+
fn flatten(self) -> Flatten<Self, <Self::Item as IntoIterator>::IntoIter>
948924
where Self: Sized,
949925
Self::Item: IntoIterator
950926
{
@@ -1087,11 +1063,10 @@ pub trait Itertools : Iterator {
10871063
///
10881064
/// itertools::assert_equal(rx.iter(), vec![1, 3, 5, 7, 9]);
10891065
/// ```
1090-
fn foreach<F>(&mut self, mut f: F)
1091-
where F: FnMut(Self::Item)
1066+
fn foreach<F>(self, mut f: F)
1067+
where F: FnMut(Self::Item),
1068+
Self: Sized,
10921069
{
1093-
// FIXME: This use of fold doesn't actually do any iterator
1094-
// specific traversal (fold requries `self`)
10951070
self.fold((), move |(), element| f(element))
10961071
}
10971072

@@ -1184,14 +1159,6 @@ pub trait Itertools : Iterator {
11841159
format::new_format_default(self, sep)
11851160
}
11861161

1187-
///
1188-
#[deprecated(note = "renamed to .format()")]
1189-
fn format_default(self, sep: &str) -> Format<Self>
1190-
where Self: Sized,
1191-
{
1192-
format::new_format_default(self, sep)
1193-
}
1194-
11951162
/// Format all iterator elements, separated by `sep`.
11961163
///
11971164
/// This is a customizable version of `.format()`.
@@ -1330,18 +1297,11 @@ pub trait Itertools : Iterator {
13301297
/// assert_eq!((0..10).fold1(|x, y| x + y).unwrap_or(0), 45);
13311298
/// assert_eq!((0..0).fold1(|x, y| x * y), None);
13321299
/// ```
1333-
fn fold1<F>(&mut self, mut f: F) -> Option<Self::Item>
1334-
where F: FnMut(Self::Item, Self::Item) -> Self::Item
1300+
fn fold1<F>(mut self, f: F) -> Option<Self::Item>
1301+
where F: FnMut(Self::Item, Self::Item) -> Self::Item,
1302+
Self: Sized,
13351303
{
1336-
match self.next() {
1337-
None => None,
1338-
Some(mut x) => {
1339-
for y in self {
1340-
x = f(x, y);
1341-
}
1342-
Some(x)
1343-
}
1344-
}
1304+
self.next().map(move |x| self.fold(x, f))
13451305
}
13461306

13471307
/// An iterator method that applies a function, producing a single, final value.
@@ -1373,7 +1333,7 @@ pub trait Itertools : Iterator {
13731333
/// // fold_while:
13741334
/// let result3 = numbers.iter().fold_while(0, |acc, x| {
13751335
/// if *x > 5 { Done(acc) } else { Continue(acc + x) }
1376-
/// });
1336+
/// }).into_inner();
13771337
///
13781338
/// // they're the same
13791339
/// assert_eq!(result, result2);
@@ -1383,23 +1343,18 @@ pub trait Itertools : Iterator {
13831343
/// The big difference between the computations of `result2` and `result3` is that while
13841344
/// `fold()` called the provided closure for every item of the callee iterator,
13851345
/// `fold_while()` actually stopped iterating as soon as it encountered `Fold::Done(_)`.
1386-
fn fold_while<B, F>(self, init: B, mut f: F) -> B
1346+
fn fold_while<B, F>(&mut self, init: B, mut f: F) -> FoldWhile<B>
13871347
where Self: Sized,
13881348
F: FnMut(B, Self::Item) -> FoldWhile<B>
13891349
{
1390-
let mut accum = init;
1391-
for item in self {
1392-
match f(accum, item) {
1393-
FoldWhile::Continue(res) => {
1394-
accum = res;
1395-
}
1396-
FoldWhile::Done(res) => {
1397-
accum = res;
1398-
break;
1399-
}
1350+
let mut acc = init;
1351+
while let Some(item) = self.next() {
1352+
match f(acc, item) {
1353+
FoldWhile::Continue(res) => acc = res,
1354+
res @ FoldWhile::Done(_) => return res,
14001355
}
14011356
}
1402-
accum
1357+
FoldWhile::Continue(acc)
14031358
}
14041359

14051360
/// Collect all iterator elements into a sorted vector in ascending order.
@@ -1679,10 +1634,28 @@ pub fn partition<'a, A: 'a, I, F>(iter: I, mut pred: F) -> usize
16791634
/// An enum used for controlling the execution of `.fold_while()`.
16801635
///
16811636
/// See [`.fold_while()`](trait.Itertools.html#method.fold_while) for more information.
1637+
#[derive(Copy, Clone, Debug)]
16821638
pub enum FoldWhile<T> {
16831639
/// Continue folding with this value
16841640
Continue(T),
16851641
/// Fold is complete and will return this value
16861642
Done(T),
16871643
}
16881644

1645+
impl<T> FoldWhile<T> {
1646+
/// Return the value in the continue or done.
1647+
pub fn into_inner(self) -> T {
1648+
match self {
1649+
FoldWhile::Continue(x) | FoldWhile::Done(x) => x,
1650+
}
1651+
}
1652+
1653+
/// Return true if `self` is `Done`, false if it is `Continue`.
1654+
pub fn is_done(&self) -> bool {
1655+
match *self {
1656+
FoldWhile::Continue(_) => false,
1657+
FoldWhile::Done(_) => true,
1658+
}
1659+
}
1660+
}
1661+

src/peeking_take_while.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ impl<'a, I, F> Iterator for PeekingTakeWhile<'a, I, F>
112112
macro_rules! peeking_next_by_clone {
113113
(@as_item $x:item) => ($x);
114114
([$($typarm:tt)*] $type_:ty) => {
115-
// FIXME: Ast coercion is dead as soon as we can dep on Rust 1.12
116-
peeking_next_by_clone! { @as_item
117115
impl<$($typarm)*> PeekingNext for $type_ {
118116
fn peeking_next<F>(&mut self, accept: F) -> Option<Self::Item>
119117
where F: FnOnce(&Self::Item) -> bool
@@ -129,7 +127,6 @@ macro_rules! peeking_next_by_clone {
129127
None
130128
}
131129
}
132-
}
133130
}
134131
}
135132

0 commit comments

Comments
 (0)