blob: 0825cb4b66926d436695fa47b66866ff0bd41ab4 [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.8.2</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-2391">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 <a href="https://doc.rust-lang.org/std/iter/trait.Iterator.html"><code>Iterator</code></a> with methods in this crate, import
the <a href="./trait.Itertools.html"><code>Itertools</code> trait</a>:</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 <a href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html" title="IntoIterator"><code>IntoIterator</code></a>):</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.24 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 <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><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.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"><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>. See <code>Itertools::minmax()</code> for
more detail.</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 <a href="https://doc.rust-lang.org/std/iter/trait.Iterator.html"><code>Iterator</code></a> 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.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 <em>equal(a, b)</em>.</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">Create an iterator that first iterates <code>i</code> and then <code>j</code>.</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 <code>Diff</code> 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.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.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.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.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.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.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></div><div class="item-right docblock-short">Iterate <code>i</code> and <code>j</code> in lock step.</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>