<!DOCTYPE html><htmllang="en"><head><metacharset="utf-8"><metaname="viewport"content="width=device-width, initial-scale=1.0"><metaname="generator"content="rustdoc"><metaname="description"content="Extra iterator adaptors, functions and macros."><title>itertools - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><linkrel="stylesheet"href="../static.files/normalize-76eba96aa4d2e634.css"><linkrel="stylesheet"href="../static.files/rustdoc-dd39b87e5fcfba68.css"><metaname="rustdoc-vars"data-root-path="../"data-static-root-path="../static.files/"data-current-crate="itertools"data-themes=""data-resource-suffix=""data-rustdoc-version="1.80.0 (051478957 2024-07-21)"data-channel="1.80.0"data-search-js="search-d52510db62a78183.js"data-settings-js="settings-4313503d2e1961c2.js"><scriptsrc="../static.files/storage-118b08c4c78b968e.js"></script><scriptdefersrc="../crates.js"></script><scriptdefersrc="../static.files/main-20a3ad099b048cf2.js"></script><noscript><linkrel="stylesheet"href="../static.files/noscript-df360f571f6edeae.css"></noscript><linkrel="alternate icon"type="image/png"href="../static.files/favicon-32x32-422f7d1d52889060.png"><linkrel="icon"type="image/svg+xml"href="../static.files/favicon-2c020d218678b618.svg"></head><bodyclass="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><navclass="mobile-topbar"><buttonclass="sidebar-menu-toggle"title="show sidebar"></button></nav><navclass="sidebar"><divclass="sidebar-crate"><h2><ahref="../itertools/index.html">itertools</a><spanclass="version">0.13.0</span></h2></div><divclass="sidebar-elems"><ulclass="block"><li><aid="all-types"href="all.html">All Items</a></li></ul><section><ulclass="block"><li><ahref="#modules">Modules</a></li><li><ahref="#macros">Macros</a></li><li><ahref="#enums">Enums</a></li><li><ahref="#traits">Traits</a></li><li><ahref="#functions">Functions</a></li></ul></section></div></nav><divclass="sidebar-resizer"></div><main><divclass="width-limiter"><rustdoc-search></rustdoc-search><sectionid="main-content"class="content"><divclass="main-heading"><h1>Crate <aclass="mod"href="#">itertools</a><buttonid="copy-path"title="Copy item path to clipboard">Copy item path</button></h1><spanclass="out-of-band"><aclass="src"href="../src/itertools/lib.rs.html#1-4365">source</a> · <buttonid="toggle-all-docs"title="collapse all docs">[<span>−</span>]</button></span></div><detailsclass="toggle top-doc"open><summaryclass="hideme"><span>Expand description</span></summary><divclass="docblock"><p>Extra iterator adaptors, functions and macros.</p>
<p>To extend <ahref="https://doc.rust-lang.org/1.80.0/core/iter/traits/iterator/trait.Iterator.html"title="trait core::iter::traits::iterator::Iterator"><code>Iterator</code></a> with methods in this crate, import
that they convert parameters using <ahref="https://doc.rust-lang.org/1.80.0/core/iter/traits/collect/trait.IntoIterator.html"title="trait core::iter::traits::collect::IntoIterator"><code>IntoIterator</code></a>):</p>
</div></details><h2id="reexports"class="section-header">Re-exports<ahref="#reexports"class="anchor">§</a></h2><ulclass="item-table"><li><divclass="item-name"><code>pub use crate::<aclass="mod"href="structs/index.html"title="mod itertools::structs">structs</a>::*;</code></div></li></ul><h2id="modules"class="section-header">Modules<ahref="#modules"class="anchor">§</a></h2><ulclass="item-table"><li><divclass="item-name"><aclass="mod"href="structs/index.html"title="mod itertools::structs">structs</a></div><divclass="desc docblock-short">The concrete iterator types.</div></li><li><divclass="item-name"><aclass="mod"href="traits/index.html"title="mod itertools::traits">traits</a></div><divclass="desc docblock-short">Traits helpful for using certain <code>Itertools</code> methods in generic contexts.</div></li></ul><h2id="macros"class="section-header">Macros<ahref="#macros"class="anchor">§</a></h2><ulclass="item-table"><li><divclass="item-name"><aclass="macro"href="macro.chain.html"title="macro itertools::chain">chain</a></div><divclass="desc docblock-short"><ahref="https://doc.rust-lang.org/1.80.0/core/iter/traits/iterator/trait.Iterator.html#method.chain"title="method core::iter::traits::iterator::Iterator::chain">Chain</a> zero or more iterators together into one sequence.</div></li><li><divclass="item-name"><aclass="macro"href="macro.iproduct.html"title="macro itertools::iproduct">iproduct</a></div><divclass="desc docblock-short">Create an iterator over the “cartesian product” of iterators.</div></li><li><divclass="item-name"><aclass="macro"href="macro.izip.html"title="macro itertools::izip">izip</a></div><divclass="desc docblock-short">Create an iterator running multiple iterators in lockstep.</div></li></ul><h2id="enums"class="section-header">Enums<ahref="#enums"class="anchor">§</a></h2><ulclass="item-table"><li><divclass="item-name"><aclass="enum"href="enum.Diff.html"title="enum itertools::Diff">Diff</a></div><divclass="desc docblock-short">A type returned by the <ahref="fn.diff_with.html"title="fn itertools::diff_with"><code>diff_with</code></a> function.</div></li><li><divclass="item-name"><aclass="enum"href="enum.Either.html"title="enum itertools::Either">Either</a></div><divclass="desc docblock-short">The enum <code>Either</code> with variants <code>Left</code> and <code>Right</code> is a general purpose
sum type with two cases.</div></li><li><divclass="item-name"><aclass="enum"href="enum.EitherOrBoth.html"title="enum itertools::EitherOrBoth">EitherOrBoth</a></div><divclass="desc docblock-short">Value that either holds a single A or B, or both.</div></li><li><divclass="item-name"><aclass="enum"href="enum.FoldWhile.html"title="enum itertools::FoldWhile">FoldWhile</a></div><divclass="desc docblock-short">An enum used for controlling the execution of <code>fold_while</code>.</div></li><li><divclass="item-name"><aclass="enum"href="enum.MinMaxResult.html"title="enum itertools::MinMaxResult">MinMaxResult</a></div><divclass="desc docblock-short"><code>MinMaxResult</code> is an enum returned by <code>minmax</code>.</div></li><li><divclass="item-name"><aclass="enum"href="enum.Position.html"title="enum itertools::Position">Position</a></div><divclass="desc docblock-short">The first component of the value yielded by <code>WithPosition</code>.
Indicates the position of this element in the iterator results.</div></li></ul><h2id="traits"class="section-header">Traits<ahref="#traits"class="anchor">§</a></h2><ulclass="item-table"><li><divclass="item-name"><aclass="trait"href="trait.Itertools.html"title="trait itertools::Itertools">Itertools</a></div><divclass="desc docblock-short">An <ahref="https://doc.rust-lang.org/1.80.0/core/iter/traits/iterator/trait.Iterator.html"title="trait core::iter::traits::iterator::Iterator"><code>Iterator</code></a> blanket implementation that provides extra adaptors and
methods.</div></li><li><divclass="item-name"><aclass="trait"href="trait.MultiUnzip.html"title="trait itertools::MultiUnzip">MultiUnzip</a></div><divclass="desc docblock-short">An iterator that can be unzipped into multiple collections.</div></li><li><divclass="item-name"><aclass="trait"href="trait.PeekingNext.html"title="trait itertools::PeekingNext">PeekingNext</a></div><divclass="desc docblock-short">An iterator that allows peeking at an element before deciding to accept it.</div></li></ul><h2id="functions"class="section-header">Functions<ahref="#functions"class="anchor">§</a></h2><ulclass="item-table"><li><divclass="item-name"><aclass="fn"href="fn.all.html"title="fn itertools::all">all</a></div><divclass="desc docblock-short">Test whether the predicate holds for all elements in the iterable.</div></li><li><divclass="item-name"><aclass="fn"href="fn.any.html"title="fn itertools::any">any</a></div><divclass="desc docblock-short">Test whether the predicate holds for any elements in the iterable.</div></li><li><divclass="item-name"><aclass="fn"href="fn.assert_equal.html"title="fn itertools::assert_equal">assert_equal</a></div><divclass="desc docblock-short">Assert that two iterables produce equal sequences, with the same
semantics as <ahref="fn.equal.html"title="fn itertools::equal"><code>equal(a, b)</code></a>.</div></li><li><divclass="item-name"><aclass="fn"href="fn.chain.html"title="fn itertools::chain">chain</a></div><divclass="desc docblock-short">Takes two iterables and creates a new iterator over both in sequence.</div></li><li><divclass="item-name"><aclass="fn"href="fn.cloned.html"title="fn itertools::cloned">cloned</a></div><divclass="desc docblock-short">Create an iterator that clones each element from <code>&T</code> to <code>T</code>.</div></li><li><divclass="item-name"><aclass="fn"href="fn.concat.html"title="fn itertools::concat">concat</a></div><divclass="desc docblock-short">Combine all an iterator’s elements into one element by using <ahref="https://doc.rust-lang.org/1.80.0/core/iter/traits/collect/trait.Extend.html"title="trait core::iter::traits::collect::Extend"><code>Extend</code></a>.</div></li><li><divclass="item-name"><aclass="fn"href="fn.cons_tuples.html"title="fn itertools::cons_tuples">cons_tuples</a></div><divclass="desc docblock-short">Create an iterator that maps for example iterators of
<code>((A, B), C)</code> to <code>(A, B, C)</code>.</div></li><li><divclass="item-name"><aclass="fn"href="fn.diff_with.html"title="fn itertools::diff_with">diff_with</a></div><divclass="desc docblock-short">Compares every element yielded by both <code>i</code> and <code>j</code> with the given function in lock-step and
returns a <ahref="enum.Diff.html"title="enum itertools::Diff"><code>Diff</code></a> which describes how <code>j</code> differs from <code>i</code>.</div></li><li><divclass="item-name"><aclass="fn"href="fn.enumerate.html"title="fn itertools::enumerate">enumerate</a></div><divclass="desc docblock-short">Iterate <code>iterable</code> with a running index.</div></li><li><divclass="item-name"><aclass="fn"href="fn.equal.html"title="fn itertools::equal">equal</a></div><divclass="desc docblock-short">Return <code>true</code> if both iterables produce equal sequences
(elements pairwise equal and sequences of the same length),
<code>false</code> otherwise.</div></li><li><divclass="item-name"><aclass="fn"href="fn.fold.html"title="fn itertools::fold">fold</a></div><divclass="desc docblock-short">Perform a fold operation over the iterable.</div></li><li><divclass="item-name"><aclass="fn"href="fn.interleave.html"title="fn itertools::interleave">interleave</a></div><divclass="desc docblock-short">Create an iterator that interleaves elements in <code>i</code> and <code>j</code>.</div></li><li><divclass="item-name"><aclass="fn"href="fn.intersperse.html"title="fn itertools::intersperse">intersperse</a></div><divclass="desc docblock-short">Iterate <code>iterable</code> with a particular value inserted between each element.</div></li><li><divclass="item-name"><aclass="fn"href="fn.intersperse_with.html"title="fn itertools::intersperse_with">intersperse_with</a></div><divclass="desc docblock-short">Iterate <code>iterable</code> with a particular value created by a function inserted
between each element.</div></li><li><divclass="item-name"><aclass="fn"href="fn.iterate.html"title="fn itertools::iterate">iterate</a></div><divclass="desc docblock-short">Creates a new iterator that infinitely applies function to value and yields results.</div></li><li><divclass="item-name"><aclass="fn"href="fn.join.html"title="fn itertools::join">join</a></div><divclass="desc docblock-short">Combine all iterator elements into one <code>String</code>, separated by <code>sep</code>.</div></li><li><divclass="item-name"><aclass="fn"href="fn.kmerge.html"title="fn itertools::kmerge">kmerge</a></div><divclass="desc docblock-short">Create an iterator that merges elements of the contained iterators using
the ordering function.</div></li><li><divclass="item-name"><aclass="fn"href="fn.kmerge_by.html"title="fn itertools::kmerge_by">kmerge_by</a></div><divclass="desc docblock-short">Create an iterator that merges elements of the contained iterators.</div></li><li><divclass="item-name"><aclass="fn"href="fn.max.html"title="fn itertools::max">max</a></div><divclass="desc docblock-short">Return the maximum value of the iterable.</div></li><li><divclass="item-name"><aclass="fn"href="fn.merge.html"title="fn itertools::merge">merge</a></div><divclass="desc docblock-short">Create an iterator that merges elements in <code>i</code> and <code>j</code>.</div></li><li><divclass="item-name"><aclass="fn"href="fn.merge_join_by.html"title="fn itertools::merge_join_by">merge_join_by</a></div><divclass="desc docblock-short">Return an iterator adaptor that merge-joins items from the two base iterators in ascending order.</div></li><li><divclass="item-name"><aclass="fn"href="fn.min.html"title="fn itertools::min">min</a></div><divclass="desc docblock-short">Return the minimum value of the iterable.</div></li><li><divclass="item-name"><aclass="fn"href="fn.multipeek.html"title="fn itertools::multipeek">multipeek</a></div><divclass="desc docblock-short">An iterator adaptor that allows the user to peek at multiple <code>.next()</code>
values without advancing the base iterator.</div></li><li><divclass="item-name"><aclass="fn"href="fn.multiunzip.html"title="fn itertools::multiunzip">multiunzip</a></div><divclass="desc docblock-short">Converts an iterator of tuples into a tuple of containers.</div></li><li><divclass="item-name"><aclass="fn"href="fn.multizip.html"title="fn itertools::multizip">multizip</a></div><divclass="desc docblock-short">An iterator that generalizes <code>.zip()</code> and allows running multiple iterators in lockstep.</div></li><li><divclass="item-name"><aclass="fn"href="fn.partition.html"title="fn itertools::partition">partition</a></div><divclass="desc docblock-short">Partition a sequence using predicate <code>pred</code> so that elements
that map to <code>true</code> are placed before elements which map to <code>false</code>.</div></li><li><divclass="item-name"><aclass="fn"href="fn.peek_nth.html"title="fn itertools::peek_nth">peek_nth</a></div><divclass="desc docblock-short">A drop-in replacement for <ahref="https://doc.rust-lang.org/1.80.0/core/iter/adapters/peekable/struct.Peekable.html"title="struct core::iter::adapters::peekable::Peekable"><code>std::iter::Peekable</code></a> which adds a <code>peek_nth</code>
method allowing the user to <code>peek</code> at a value several iterations forward
without advancing the base iterator.</div></li><li><divclass="item-name"><aclass="fn"href="fn.process_results.html"title="fn itertools::process_results">process_results</a></div><divclass="desc docblock-short">“Lift” a function of the values of an iterator so that it can process
an iterator of <code>Result</code> values instead.</div></li><li><divclass="item-name"><aclass="fn"href="fn.put_back.html"title="fn itertools::put_back">put_back</a></div><divclass="desc docblock-short">Create an iterator where you can put back a single item</div></li><li><divclass="item-name"><aclass="fn"href="fn.put_back_n.html"title="fn itertools::put_back_n">put_back_n</a></div><divclass="desc docblock-short">Create an iterator where you can put back multiple values to the front
of the iteration.</div></li><li><divclass="item-name"><aclass="fn"href="fn.rciter.html"title="fn itertools::rciter">rciter</a></div><divclass="desc docblock-short">Return an iterator inside a <code>Rc<RefCell<_>></code> wrapper.</div></li><li><divclass="item-name"><aclass="fn"href="fn.repeat_n.html"title="fn itertools::repeat_n">repeat_n</a></div><divclass="desc docblock-short">Create an iterator that produces <code>n</code> repetitions of <code>element</code>.</div></li><li><divclass="item-name"><aclass="fn"href="fn.rev.html"title="fn itertools::rev">rev</a></div><divclass="desc docblock-short">Iterate <code>iterable</code> in reverse.</div></li><li><divclass="item-name"><aclass="fn"href="fn.sorted.html"title="fn itertools::sorted">sorted</a></div><divclass="desc docblock-short">Sort all iterator elements into a new iterator in ascending order.</div></li><li><divclass="item-name"><aclass="fn"href="fn.sorted_unstable.html"title="fn itertools::sorted_unstable">sorted_unstable</a></div><divclass="desc docblock-short">Sort all iterator elements into a new iterator in ascending order.
This sort is unstable (i.e., may reorder equal elements).</div></li><li><divclass="item-name"><aclass="fn"href="fn.unfold.html"title="fn itertools::unfold">unfold</a><spanclass="stab deprecated"title="">Deprecated</span></div><divclass="desc docblock-short">Creates a new unfold source with the specified closure as the “iterator
function” and an initial state to eventually pass to the closure</div></li><li><divclass="item-name"><aclass="fn"href="fn.zip.html"title="fn itertools::zip">zip</a><spanclass="stab deprecated"title="">Deprecated</span></div><divclass="desc docblock-short">Converts the arguments to iterators and zips them.</div></li><li><divclass="item-name"><aclass="fn"href="fn.zip_eq.html"title="fn itertools::zip_eq">zip_eq</a></div><divclass="desc docblock-short">Zips two iterators but <strong>panics</strong> if they are not of the same length.</div></li></ul></section></div></main></body></html>