Extra iterator adaptors, functions and macros.
Please read the API documentation here
__
__ https://docs.rs/itertools/
|buildstatus| |crates|_
.. |buildstatus| image:: https://travis-ci.org/rust-itertools/itertools.svg?branch=master .. _buildstatus: https://travis-ci.org/rust-itertools/itertools
.. |crates| image:: http://meritbadge.herokuapp.com/itertools .. _crates: https://crates.io/crates/itertools
How to use with cargo:
.. code:: toml
[dependencies]
itertools = "0.8"
How to use in your crate:
.. code:: rust
#[macro_use] extern crate itertools;
use itertools::Itertools;
For new features, please first consider filing a PR to rust-lang/rust <https://github.com/rust-lang/rust/>
_,
adding your new feature to the Iterator
trait of the standard library, if you believe it is reasonable.
If it isn't accepted there, proposing it for inclusion in itertools
is a good idea.
The reason for doing is this is so that we avoid future breakage as with .flatten()
.
However, if your feature involves heap allocation, such as storing elements in a Vec<T>
,
then it can't be accepted into libcore
, and you should propose it for itertools
directly instead.
0.8.1
Added a .exactly_one() <https://docs.rs/itertools/0.8.1/itertools/trait.Itertools.html#method.exactly_one>
_
iterator method that, on success, extracts the single value of an
iterator
; by @Xaeroxe <https://github.com/Xaeroxe>
_
Added combinatory iterator adaptors:
.permutations(k) <https://docs.rs/itertools/0.8.1/itertools/trait.Itertools.html#method.permutations>
_:
[0, 1, 2].iter().permutations(2)
yields
.. code:: rust
[ vec![0, 1], vec![0, 2], vec![1, 0], vec![1, 2], vec![2, 0], vec![2, 1], ]
; by @tobz1000 <https://github.com/tobz1000>
_
.combinations_with_replacement(k) <https://docs.rs/itertools/0.8.1/itertools/trait.Itertools.html#method.combinations_with_replacement>
_:
[0, 1, 2].iter().combinations_with_replacement(2)
yields
.. code:: rust
[ vec![0, 0], vec![0, 1], vec![0, 2], vec![1, 1], vec![1, 2], vec![2, 2], ]
; by @tommilligan <https://github.com/tommilligan>
_
For reference, these methods join the already existing
.combinations(k) <https://docs.rs/itertools/0.8.1/itertools/trait.Itertools.html#method.combinations>
_:
[0, 1, 2].iter().combinations(2)
yields
.. code:: rust
[ vec![0, 1], vec![0, 2], vec![1, 2], ]
Improved the performance of .fold() <https://docs.rs/itertools/0.8.1/itertools/trait.Itertools.html#method.fold>
-based internal iteration for the
.intersperse() <https://docs.rs/itertools/0.8.1/itertools/trait.Itertools.html#method.intersperse>
iterator
; by @jswrenn <https://github.com/jswrenn>
_
Added
.dedup_by() <https://docs.rs/itertools/0.8.1/itertools/trait.Itertools.html#method.dedup_by>
,
.merge_by() <https://docs.rs/itertools/0.8.1/itertools/trait.Itertools.html#method.merge_by>
and .kmerge_by() <https://docs.rs/itertools/0.8.1/itertools/trait.Itertools.html#method.kmerge_by>
_
adaptors that work like
.dedup() <https://docs.rs/itertools/0.8.1/itertools/trait.Itertools.html#method.dedup>
,
.merge() <https://docs.rs/itertools/0.8.1/itertools/trait.Itertools.html#method.merge>
and
.kmerge() <https://docs.rs/itertools/0.8.1/itertools/trait.Itertools.html#method.kmerge>
,
but taking an additional custom comparison closure parameter.
; by @phimuemue <https://github.com/phimuemue>
Improved the performance of .all_equal() <https://docs.rs/itertools/0.8.1/itertools/trait.Itertools.html#method.all_equal>
_
; by @fyrchik <https://github.com/fyrchik>
_
Loosened the bounds on .partition_map() <https://docs.rs/itertools/0.8.1/itertools/trait.Itertools.html#method.partition_map>
_
to take just a FnMut
closure rather than a Fn
closure, and made its
implementation use internal iteration for better performance
; by @danielhenrymantilla <https://github.com/danielhenrymantilla>
_
Added convenience methods to
EitherOrBoth <https://docs.rs/itertools/0.8.1/itertools/enum.EitherOrBoth.html>
_ elements yielded from the
.zip_longest() <https://docs.rs/itertools/0.8.1/itertools/trait.Itertools.html#method.zip_longest>
_ iterator adaptor
; by @Avi-D-coder <https://github.com/Avi-D-coder>
_
Added .sum1() <https://docs.rs/itertools/0.8.1/itertools/trait.Itertools.html#method.sum1>
_
and .product1() <https://docs.rs/itertools/0.8.1/itertools/trait.Itertools.html#method.product1>
_
iterator methods that respectively try to return the sum and the product of
the elements of an iterator when it is not empty, otherwise they return
None
; by @Emerentius <https://github.com/Emerentius>
_
0.8.0
.map_into()
for conversions using Into
by @vornerItertools
docs by @JohnHeitmann.sorted/_by/_by_key()
is now an iterator, not a Vec.izip!(x, y)
macro with exactly two arguments
is now the usual Iterator::zip
..flatten()
in favour of std's .flatten()
.foreach()
in favour of std's .for_each()
.step()
in favour of std's .step_by()
repeat_call
in favour of std's repeat_with
.fold_while()
in favour of std's .try_fold()
0.7.11
EitherOrBoth
, making it more similar to Option
and Either
by @jethrogb0.7.10
0.7.9
FoldWhile
type now implements Eq
and PartialEq
by @jturner3140.7.8
.tree_fold1()
which is like .fold1()
except items are combined in a tree structure (see its docs).
By @scottmcmDebug
impls by @phimuemue: KMerge, KMergeBy, MergeJoinBy,
ConsTuples, Intersperse, ProcessResults, RcIter, Tee, TupleWindows, Tee,
ZipLongest, ZipEq, Zip.0.7.7
.into_group_map() -> HashMap<K, Vec<V>>
which turns an iterator of (K, V)
elements into such a hash table,
where values are grouped by key. By @tobz1000flatten
for the .flatten()
adaptor.
NOTE: recent Rust nightlies have Iterator::flatten
and thus a clash
with our flatten adaptor. One workaround is to use the itertools flatten
free function.0.7.6
.multi_cartesian_product()
which is an n-ary product
iterator by @tobz1000.sorted_by_key()
by @Xion.count()
for .unique()
and .unique_by()
0.7.5
.multipeek()
now implements PeekingNext
, by @nicopap.0.7.4
.update()
by @lucasem; this adaptor is used
to modify an element before passing it on in an iterator chain.0.7.3
.collect_tuple()
by @matklad; it makes a tuple out of
the iterator's elements if the number of them matches exactly.fold
and collect
for .map_results()
which means
it reuses the code of the standard .map()
for these methods.0.7.2
.merge_join_by
by @srijs; a heterogeneous merge join
for two ordered sequences.0.7.1
must_use
reminder that the standard library adaptors do, by @matematikaedit and @bluss
“iterator adaptors are lazy and do nothing unless consumed”.0.7.0
Faster izip!()
by @krdln
izip!()
is now a wrapper for repeated regular .zip()
and
a single .map()
. This means it optimizes as well as the standard
library .zip()
it uses.
Note: multizip
and izip!()
are now different! The former
has a named type but the latter optimizes better.
Faster .unique()
no_std
support, which is opt-in!
Many lovable features are still there without std, like izip!()
or .format()
or .merge()
, but not those that use collections.
Trait bounds were required up front instead of just on the type:
group_by
's PartialEq
by @Phlosioneer and repeat_call
's
FnMut
.
Zip::new
— use izip!()
or multizip()
0.6.5
.cartesian_product()
's fold (which only was visible for
unfused iterators).0.6.4
fold
implementations for .cartesian_product()
and
cons_tuples()
, which improves their performance in fold, foreach, and
iterator consumers derived from them.0.6.3
.positions(predicate)
by @tmccombs0.6.2
process_results
which can “lift” a function of the regular
values of an iterator so that it can process the Ok
values from an
iterator of Results
instead, by @shepmaster.concat()
which combines all iterator elements
into a single collection using the Extend
trait, by @srijs0.6.1
.all_equal()
by @phimuemue0.6.0
.flatten()
does not implement double ended iteration anymore.fold_while()
uses &mut self
and returns FoldWhile<T>
, for
composability (#168).foreach()
and .fold1()
use self
, like .fold()
does..combinations(0)
now produces a single empty vector. (#174)0.5.10
.kmerge_by()
(and corresponding free function).kmerge()
and .minmax()
to PartialOrd.0.5.9
.reset_peek()
0.5.8
.peeking_take_while()
and its trait PeekingNext
.0.5.7
.with_position()
VecDeque
.0.5.6
.map_results()
0.5.5
Debug
repeat_n
. RepeatN::new
is now
deprecated.0.5.4
iterate
, that takes a seed and a
closure.0.5.3
.fold()
for flatten and put back. .foreach()
now uses fold on the iterator, to pick up any iterator specific loop
implementation..combinations(n)
asserts up front that n != 0
, instead of
running into an error on the second iterator element.0.5.2
.tuples::<T>()
that iterates by two, three or four elements at
a time (where T
is a tuple type)..tuple_windows::<T>()
that iterates using a window of the
two, three or four most recent elements..next_tuple::<T>()
method, that picks the next two, three or four
elements in one go..interleave()
now has an accurate size hint.0.5.1
0.5.0
Release announcement <http://bluss.github.io/rust/2016/09/26/itertools-0.5.0/>
_Renamed:
combinations is now tuple_combinations
Partition
enum is now Either
Module reorganization:
All iterator structs are under itertools::structs
but also
reexported to the top level, for backwards compatibility
All free functions are reexported at the root, itertools::free
will
be removed in the next version
Removed:
ZipSlices, use .zip() instead
new
constructors on iterator structs, use Itertools trait or free
functions insteaditertools::size_hint
is now private
Behaviour changes:
format and format_with helpers now panic if you try to format them more than once.
repeat_call
is not double ended anymore
New features:
tuple flattening iterator is constructible with cons_tuples
Either
from the either
crate. Either<L, R>
is an iterator when L, R
are.MinMaxResult
now implements Copy and Clone0.4.19
.minmax_by()
itertools::free::cloned
itertools::free::rciter
.step(n)
slightly to take advantage of specialized Fuse better.0.4.18
Only changes related to the "unstable" crate feature. This feature is more or less deprecated.
Use deprecated warnings when unstable is enabled. .enumerate_from() will be removed imminently since it's using a deprecated libstd trait.
0.4.17
0.4.16
0.4.15
0.4.14
0.4.13
0.4.12
0.4.11
0.4.10
0.4.9
0.4.8
0.4.7
0.4.6
itertools::free
with free function variants of common
iterator adaptors and methods.
For example enumerate(iterable)
, rev(iterable)
, and so on.0.4.5
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
Breaking changes:
Return types of .merge() and .merge_by() renamed and changed
0.3.25
0.3.24
0.3.23
0.3.22
0.3.21
Debug
impl for Format
, it will have different use later0.3.20
0.3.19
0.3.17
0.3.16
0.3.15
0.3.14
0.3.13
0.3.11
0.3.10
0.3.8
0.3.7
0.3.6
0.3.5
0.3.4
0.3.3
Dual-licensed to be compatible with the Rust project.
Licensed under the Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0 or the MIT license http://opensource.org/licenses/MIT, at your option. This file may not be copied, modified, or distributed except according to those terms.