blob: 2a7bb698a12da5694ba0bf368f784e794eca4aa7 [file] [log] [blame]
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Extra iterator adaptors, functions and macros."><meta name="keywords" content="rust, rustlang, rust-lang, itertools"><title>itertools - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../normalize.css"><link rel="stylesheet" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../ayu.css" disabled><link rel="stylesheet" href="../dark.css" disabled><link rel="stylesheet" href="../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../storage.js"></script><script defer src="../crates.js"></script><script defer src="../main.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../favicon.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="sidebar-logo" href="../itertools/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../itertools/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">Crate itertools</a></h2><div class="sidebar-elems"><ul class="block"><li class="version">Version 0.10.5</li><li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#modules">Modules</a></li><li><a href="#macros">Macros</a></li><li><a href="#enums">Enums</a></li><li><a href="#traits">Traits</a></li><li><a href="#functions">Functions</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Crate <a class="mod" href="#">itertools</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../src/itertools/lib.rs.html#1-3784">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Extra iterator adaptors, functions and macros.</p>
<p>To extend [<code>Iterator</code>] with methods in this crate, import
the <a href="trait.Itertools.html" title="Itertools"><code>Itertools</code></a> trait:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;</code></pre></div>
<p>Now, new methods like <a href="trait.Itertools.html#method.interleave"><code>interleave</code></a>
are available on all iterators:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
<span class="kw">let </span>it = (<span class="number">1</span>..<span class="number">3</span>).interleave(<span class="macro">vec!</span>[-<span class="number">1</span>, -<span class="number">2</span>]);
itertools::assert_equal(it, <span class="macro">vec!</span>[<span class="number">1</span>, -<span class="number">1</span>, <span class="number">2</span>, -<span class="number">2</span>]);</code></pre></div>
<p>Most iterator methods are also provided as functions (with the benefit
that they convert parameters using [<code>IntoIterator</code>]):</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::interleave;
<span class="kw">for </span>elt <span class="kw">in </span>interleave(<span class="kw-2">&amp;</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>], <span class="kw-2">&amp;</span>[<span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>]) {
<span class="comment">/* loop body */
</span>}</code></pre></div>
<h3 id="crate-features"><a href="#crate-features">Crate Features</a></h3>
<ul>
<li><code>use_std</code>
<ul>
<li>Enabled by default.</li>
<li>Disable to compile itertools using <code>#![no_std]</code>. This disables
any items that depend on collections (like <code>group_by</code>, <code>unique</code>,
<code>kmerge</code>, <code>join</code> and many more).</li>
</ul>
</li>
</ul>
<h3 id="rust-version"><a href="#rust-version">Rust Version</a></h3>
<p>This version of itertools requires Rust 1.32 or later.</p>
</div></details><h2 id="reexports" class="small-section-header"><a href="#reexports">Re-exports</a></h2><div class="item-table"><div class="item-row"><div class="item-left import-item"><code>pub use crate::<a class="mod" href="structs/index.html" title="mod itertools::structs">structs</a>::*;</code></div></div></div><h2 id="modules" class="small-section-header"><a href="#modules">Modules</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="mod" href="structs/index.html" title="itertools::structs mod">structs</a></div><div class="item-right docblock-short">The concrete iterator types.</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="traits/index.html" title="itertools::traits mod">traits</a></div><div class="item-right docblock-short">Traits helpful for using certain <code>Itertools</code> methods in generic contexts.</div></div></div><h2 id="macros" class="small-section-header"><a href="#macros">Macros</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.chain.html" title="itertools::chain macro">chain</a></div><div class="item-right docblock-short"><a href="Iterator::chain">Chain</a> zero or more iterators together into one sequence.</div></div><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.iproduct.html" title="itertools::iproduct macro">iproduct</a></div><div class="item-right docblock-short">Create an iterator over the “cartesian product” of iterators.</div></div><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.izip.html" title="itertools::izip macro">izip</a></div><div class="item-right docblock-short">Create an iterator running multiple iterators in lockstep.</div></div></div><h2 id="enums" class="small-section-header"><a href="#enums">Enums</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.Diff.html" title="itertools::Diff enum">Diff</a></div><div class="item-right docblock-short">A type returned by the <a href="fn.diff_with.html" title="diff_with"><code>diff_with</code></a> function.</div></div><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.Either.html" title="itertools::Either enum">Either</a></div><div class="item-right 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></div><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.EitherOrBoth.html" title="itertools::EitherOrBoth enum">EitherOrBoth</a></div><div class="item-right docblock-short">Value that either holds a single A or B, or both.</div></div><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.FoldWhile.html" title="itertools::FoldWhile enum">FoldWhile</a></div><div class="item-right docblock-short">An enum used for controlling the execution of <code>fold_while</code>.</div></div><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.MinMaxResult.html" title="itertools::MinMaxResult enum">MinMaxResult</a></div><div class="item-right docblock-short"><code>MinMaxResult</code> is an enum returned by <code>minmax</code>.</div></div><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.Position.html" title="itertools::Position enum">Position</a></div><div class="item-right docblock-short">A value yielded by <code>WithPosition</code>.
Indicates the position of this element in the iterator results.</div></div></div><h2 id="traits" class="small-section-header"><a href="#traits">Traits</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.Itertools.html" title="itertools::Itertools trait">Itertools</a></div><div class="item-right docblock-short">An [<code>Iterator</code>] blanket implementation that provides extra adaptors and
methods.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.MultiUnzip.html" title="itertools::MultiUnzip trait">MultiUnzip</a></div><div class="item-right docblock-short">An iterator that can be unzipped into multiple collections.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.PeekingNext.html" title="itertools::PeekingNext trait">PeekingNext</a></div><div class="item-right docblock-short">An iterator that allows peeking at an element before deciding to accept it.</div></div></div><h2 id="functions" class="small-section-header"><a href="#functions">Functions</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.all.html" title="itertools::all fn">all</a></div><div class="item-right docblock-short">Test whether the predicate holds for all elements in the iterable.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.any.html" title="itertools::any fn">any</a></div><div class="item-right docblock-short">Test whether the predicate holds for any elements in the iterable.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.assert_equal.html" title="itertools::assert_equal fn">assert_equal</a></div><div class="item-right docblock-short">Assert that two iterables produce equal sequences, with the same
semantics as <a href="fn.equal.html"><code>equal(a, b)</code></a>.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.chain.html" title="itertools::chain fn">chain</a></div><div class="item-right docblock-short">Takes two iterables and creates a new iterator over both in sequence. </div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.cloned.html" title="itertools::cloned fn">cloned</a></div><div class="item-right docblock-short">Create an iterator that clones each element from &amp;T to T</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.concat.html" title="itertools::concat fn">concat</a></div><div class="item-right docblock-short">Combine all an iterator’s elements into one element by using [<code>Extend</code>].</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.cons_tuples.html" title="itertools::cons_tuples fn">cons_tuples</a></div><div class="item-right docblock-short">Create an iterator that maps for example iterators of
<code>((A, B), C)</code> to <code>(A, B, C)</code>.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.diff_with.html" title="itertools::diff_with fn">diff_with</a></div><div class="item-right 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 <a href="enum.Diff.html" title="Diff"><code>Diff</code></a> which describes how <code>j</code> differs from <code>i</code>.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.enumerate.html" title="itertools::enumerate fn">enumerate</a></div><div class="item-right docblock-short">Iterate <code>iterable</code> with a running index.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.equal.html" title="itertools::equal fn">equal</a></div><div class="item-right 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></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.fold.html" title="itertools::fold fn">fold</a></div><div class="item-right docblock-short">Perform a fold operation over the iterable.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.interleave.html" title="itertools::interleave fn">interleave</a></div><div class="item-right docblock-short">Create an iterator that interleaves elements in <code>i</code> and <code>j</code>.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.intersperse.html" title="itertools::intersperse fn">intersperse</a></div><div class="item-right docblock-short">Iterate <code>iterable</code> with a particular value inserted between each element.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.intersperse_with.html" title="itertools::intersperse_with fn">intersperse_with</a></div><div class="item-right docblock-short">Iterate <code>iterable</code> with a particular value created by a function inserted
between each element.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.iterate.html" title="itertools::iterate fn">iterate</a></div><div class="item-right docblock-short">Creates a new iterator that infinitely applies function to value and yields results.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.join.html" title="itertools::join fn">join</a></div><div class="item-right docblock-short">Combine all iterator elements into one String, separated by <code>sep</code>.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.kmerge.html" title="itertools::kmerge fn">kmerge</a></div><div class="item-right docblock-short">Create an iterator that merges elements of the contained iterators using
the ordering function.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.kmerge_by.html" title="itertools::kmerge_by fn">kmerge_by</a></div><div class="item-right docblock-short">Create an iterator that merges elements of the contained iterators.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.max.html" title="itertools::max fn">max</a></div><div class="item-right docblock-short">Return the maximum value of the iterable.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.merge.html" title="itertools::merge fn">merge</a></div><div class="item-right docblock-short">Create an iterator that merges elements in <code>i</code> and <code>j</code>.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.merge_join_by.html" title="itertools::merge_join_by fn">merge_join_by</a></div><div class="item-right docblock-short">Return an iterator adaptor that merge-joins items from the two base iterators in ascending order.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.min.html" title="itertools::min fn">min</a></div><div class="item-right docblock-short">Return the minimum value of the iterable.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.multipeek.html" title="itertools::multipeek fn">multipeek</a></div><div class="item-right docblock-short">An iterator adaptor that allows the user to peek at multiple <code>.next()</code>
values without advancing the base iterator.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.multiunzip.html" title="itertools::multiunzip fn">multiunzip</a></div><div class="item-right docblock-short">Converts an iterator of tuples into a tuple of containers.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.multizip.html" title="itertools::multizip fn">multizip</a></div><div class="item-right docblock-short">An iterator that generalizes <em>.zip()</em> and allows running multiple iterators in lockstep.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.partition.html" title="itertools::partition fn">partition</a></div><div class="item-right 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></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.peek_nth.html" title="itertools::peek_nth fn">peek_nth</a></div><div class="item-right docblock-short">A drop-in replacement for [<code>std::iter::Peekable</code>] 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></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.process_results.html" title="itertools::process_results fn">process_results</a></div><div class="item-right 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></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.put_back.html" title="itertools::put_back fn">put_back</a></div><div class="item-right docblock-short">Create an iterator where you can put back a single item</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.put_back_n.html" title="itertools::put_back_n fn">put_back_n</a></div><div class="item-right docblock-short">Create an iterator where you can put back multiple values to the front
of the iteration.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.rciter.html" title="itertools::rciter fn">rciter</a></div><div class="item-right docblock-short">Return an iterator inside a <code>Rc&lt;RefCell&lt;_&gt;&gt;</code> wrapper.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.repeat_call.html" title="itertools::repeat_call fn">repeat_call</a><span class="stab deprecated" title="">Deprecated</span></div><div class="item-right docblock-short">An iterator source that produces elements indefinitely by calling
a given closure.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.repeat_n.html" title="itertools::repeat_n fn">repeat_n</a></div><div class="item-right docblock-short">Create an iterator that produces <code>n</code> repetitions of <code>element</code>.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.rev.html" title="itertools::rev fn">rev</a></div><div class="item-right docblock-short">Iterate <code>iterable</code> in reverse.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.sorted.html" title="itertools::sorted fn">sorted</a></div><div class="item-right docblock-short">Sort all iterator elements into a new iterator in ascending order.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.unfold.html" title="itertools::unfold fn">unfold</a></div><div class="item-right 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></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.zip.html" title="itertools::zip fn">zip</a><span class="stab deprecated" title="">Deprecated</span></div><div class="item-right docblock-short">Converts the arguments to iterators and zips them.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.zip_eq.html" title="itertools::zip_eq fn">zip_eq</a></div><div class="item-right docblock-short">Iterate <code>i</code> and <code>j</code> in lock step.</div></div></div></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="itertools" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html>