Files
google-apis-rs/itertools/index.html
2021-04-02 00:20:57 +08:00

112 lines
18 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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="API documentation for the Rust `itertools` crate."><meta name="keywords" content="rust, rustlang, rust-lang, itertools"><title>itertools - Rust</title><link rel="stylesheet" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../ayu.css" disabled ><script id="default-settings"></script><script src="../storage.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../favicon.svg">
<link rel="alternate icon" type="image/png" href="../favicon-16x16.png">
<link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><body class="rustdoc mod"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">&#9776;</div><a href='../itertools/index.html'><div class='logo-container rust-logo'><img src='../rust-logo.png' alt='logo'></div></a><p class="location">Crate itertools</p><div class="block version"><p>Version 0.10.0</p></div><div class="sidebar-elems"><a id="all-types" href="all.html"><p>See all itertools's items</p></a><div class="block items"><ul><li><a href="#reexports">Re-exports</a></li><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></div><p class="location"></p><div id="sidebar-vars" data-name="itertools" data-ty="mod" data-relpath="../"></div></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><button type="button" class="help-button">?</button>
<a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="in-band">Crate <a class="mod" href="">itertools</a></span><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span><a class="srclink" href="../src/itertools/lib.rs.html#1-3196" title="goto source code">[src]</a></span></h1><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">
<span class="kw">use</span> <span class="ident">itertools</span>::<span class="ident">Itertools</span>;</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">
<span class="kw">use</span> <span class="ident">itertools</span>::<span class="ident">Itertools</span>;
<span class="kw">let</span> <span class="ident">it</span> <span class="op">=</span> (<span class="number">1</span>..<span class="number">3</span>).<span class="ident">interleave</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="op">-</span><span class="number">1</span>, <span class="op">-</span><span class="number">2</span>]);
<span class="ident">itertools</span>::<span class="ident">assert_equal</span>(<span class="ident">it</span>, <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="op">-</span><span class="number">1</span>, <span class="number">2</span>, <span class="op">-</span><span class="number">2</span>]);</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">
<span class="kw">use</span> <span class="ident">itertools</span>::<span class="ident">interleave</span>;
<span class="kw">for</span> <span class="ident">elt</span> <span class="kw">in</span> <span class="ident">interleave</span>(<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>
}</pre></div>
<h2 id="crate-features" class="section-header"><a href="#crate-features">Crate Features</a></h2>
<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>
<h2 id="rust-version" class="section-header"><a href="#rust-version">Rust Version</a></h2>
<p>This version of itertools requires Rust 1.32 or later.</p>
</div><h2 id="reexports" class="section-header"><a href="#reexports">Re-exports</a></h2>
<table><tr><td><code>pub use crate::<a class="mod" href="../itertools/structs/index.html" title="mod itertools::structs">structs</a>::*;</code></td></tr></table><h2 id="modules" class="section-header"><a href="#modules">Modules</a></h2>
<table><tr class="module-item"><td><a class="mod" href="structs/index.html" title="itertools::structs mod">structs</a></td><td class="docblock-short"><p>The concrete iterator types.</p>
</td></tr><tr class="module-item"><td><a class="mod" href="traits/index.html" title="itertools::traits mod">traits</a></td><td class="docblock-short"><p>Traits helpful for using certain <code>Itertools</code> methods in generic contexts.</p>
</td></tr></table><h2 id="macros" class="section-header"><a href="#macros">Macros</a></h2>
<table><tr class="module-item"><td><a class="macro" href="macro.iproduct.html" title="itertools::iproduct macro">iproduct</a></td><td class="docblock-short"><p>Create an iterator over the “cartesian product” of iterators.</p>
</td></tr><tr class="module-item"><td><a class="macro" href="macro.izip.html" title="itertools::izip macro">izip</a></td><td class="docblock-short"><p>Create an iterator running multiple iterators in lockstep.</p>
</td></tr></table><h2 id="enums" class="section-header"><a href="#enums">Enums</a></h2>
<table><tr class="module-item"><td><a class="enum" href="enum.Diff.html" title="itertools::Diff enum">Diff</a></td><td class="docblock-short"><p>A type returned by the <a href="./fn.diff_with.html"><code>diff_with</code></a> function.</p>
</td></tr><tr class="module-item"><td><a class="enum" href="enum.Either.html" title="itertools::Either enum">Either</a></td><td class="docblock-short"><p>The enum <code>Either</code> with variants <code>Left</code> and <code>Right</code> is a general purpose
sum type with two cases.</p>
</td></tr><tr class="module-item"><td><a class="enum" href="enum.EitherOrBoth.html" title="itertools::EitherOrBoth enum">EitherOrBoth</a></td><td class="docblock-short"><p>Value that either holds a single A or B, or both.</p>
</td></tr><tr class="module-item"><td><a class="enum" href="enum.FoldWhile.html" title="itertools::FoldWhile enum">FoldWhile</a></td><td class="docblock-short"><p>An enum used for controlling the execution of <code>.fold_while()</code>.</p>
</td></tr><tr class="module-item"><td><a class="enum" href="enum.MinMaxResult.html" title="itertools::MinMaxResult enum">MinMaxResult</a></td><td class="docblock-short"><p><code>MinMaxResult</code> is an enum returned by <code>minmax</code>. See <code>Itertools::minmax()</code> for
more detail.</p>
</td></tr><tr class="module-item"><td><a class="enum" href="enum.Position.html" title="itertools::Position enum">Position</a></td><td class="docblock-short"><p>A value yielded by <code>WithPosition</code>.
Indicates the position of this element in the iterator results.</p>
</td></tr></table><h2 id="traits" class="section-header"><a href="#traits">Traits</a></h2>
<table><tr class="module-item"><td><a class="trait" href="trait.Itertools.html" title="itertools::Itertools trait">Itertools</a></td><td class="docblock-short"><p>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.</p>
</td></tr><tr class="module-item"><td><a class="trait" href="trait.PeekingNext.html" title="itertools::PeekingNext trait">PeekingNext</a></td><td class="docblock-short"><p>An iterator that allows peeking at an element before deciding to accept it.</p>
</td></tr></table><h2 id="functions" class="section-header"><a href="#functions">Functions</a></h2>
<table><tr class="module-item"><td><a class="fn" href="fn.all.html" title="itertools::all fn">all</a></td><td class="docblock-short"><p>Test whether the predicate holds for all elements in the iterable.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.any.html" title="itertools::any fn">any</a></td><td class="docblock-short"><p>Test whether the predicate holds for any elements in the iterable.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.assert_equal.html" title="itertools::assert_equal fn">assert_equal</a></td><td class="docblock-short"><p>Assert that two iterables produce equal sequences, with the same
semantics as <em>equal(a, b)</em>.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.chain.html" title="itertools::chain fn">chain</a></td><td class="docblock-short"><p>Create an iterator that first iterates <code>i</code> and then <code>j</code>.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.cloned.html" title="itertools::cloned fn">cloned</a></td><td class="docblock-short"><p>Create an iterator that clones each element from &amp;T to T</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.concat.html" title="itertools::concat fn">concat</a></td><td class="docblock-short"><p>Combine all an iterator's elements into one element by using <code>Extend</code>.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.cons_tuples.html" title="itertools::cons_tuples fn">cons_tuples</a></td><td class="docblock-short"><p>Create an iterator that maps for example iterators of
<code>((A, B), C)</code> to <code>(A, B, C)</code>.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.diff_with.html" title="itertools::diff_with fn">diff_with</a></td><td class="docblock-short"><p>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>.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.enumerate.html" title="itertools::enumerate fn">enumerate</a></td><td class="docblock-short"><p>Iterate <code>iterable</code> with a running index.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.equal.html" title="itertools::equal fn">equal</a></td><td class="docblock-short"><p>Return <code>true</code> if both iterables produce equal sequences
(elements pairwise equal and sequences of the same length),
<code>false</code> otherwise.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.fold.html" title="itertools::fold fn">fold</a></td><td class="docblock-short"><p>Perform a fold operation over the iterable.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.interleave.html" title="itertools::interleave fn">interleave</a></td><td class="docblock-short"><p>Create an iterator that interleaves elements in <code>i</code> and <code>j</code>.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.iterate.html" title="itertools::iterate fn">iterate</a></td><td class="docblock-short"><p>Creates a new iterator that infinitely applies function to value and yields results.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.join.html" title="itertools::join fn">join</a></td><td class="docblock-short"><p>Combine all iterator elements into one String, seperated by <code>sep</code>.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.kmerge.html" title="itertools::kmerge fn">kmerge</a></td><td class="docblock-short"><p>Create an iterator that merges elements of the contained iterators using
the ordering function.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.kmerge_by.html" title="itertools::kmerge_by fn">kmerge_by</a></td><td class="docblock-short"><p>Create an iterator that merges elements of the contained iterators.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.max.html" title="itertools::max fn">max</a></td><td class="docblock-short"><p>Return the maximum value of the iterable.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.merge.html" title="itertools::merge fn">merge</a></td><td class="docblock-short"><p>Create an iterator that merges elements in <code>i</code> and <code>j</code>.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.merge_join_by.html" title="itertools::merge_join_by fn">merge_join_by</a></td><td class="docblock-short"><p>Return an iterator adaptor that merge-joins items from the two base iterators in ascending order.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.min.html" title="itertools::min fn">min</a></td><td class="docblock-short"><p>Return the minimum value of the iterable.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.multipeek.html" title="itertools::multipeek fn">multipeek</a></td><td class="docblock-short"><p>An iterator adaptor that allows the user to peek at multiple <code>.next()</code>
values without advancing the base iterator.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.multizip.html" title="itertools::multizip fn">multizip</a></td><td class="docblock-short"><p>An iterator that generalizes <em>.zip()</em> and allows running multiple iterators in lockstep.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.partition.html" title="itertools::partition fn">partition</a></td><td class="docblock-short"><p>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>.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.peek_nth.html" title="itertools::peek_nth fn">peek_nth</a></td><td class="docblock-short"><p>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.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.process_results.html" title="itertools::process_results fn">process_results</a></td><td class="docblock-short"><p>“Lift” a function of the values of an iterator so that it can process
an iterator of <code>Result</code> values instead.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.put_back.html" title="itertools::put_back fn">put_back</a></td><td class="docblock-short"><p>Create an iterator where you can put back a single item</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.put_back_n.html" title="itertools::put_back_n fn">put_back_n</a></td><td class="docblock-short"><p>Create an iterator where you can put back multiple values to the front
of the iteration.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.rciter.html" title="itertools::rciter fn">rciter</a></td><td class="docblock-short"><p>Return an iterator inside a <code>Rc&lt;RefCell&lt;_&gt;&gt;</code> wrapper.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.repeat_call.html" title="itertools::repeat_call fn">repeat_call</a></td><td class="docblock-short"><span class="stab deprecated" title="">Deprecated</span><p>An iterator source that produces elements indefinitely by calling
a given closure.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.repeat_n.html" title="itertools::repeat_n fn">repeat_n</a></td><td class="docblock-short"><p>Create an iterator that produces <code>n</code> repetitions of <code>element</code>.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.rev.html" title="itertools::rev fn">rev</a></td><td class="docblock-short"><p>Iterate <code>iterable</code> in reverse.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.sorted.html" title="itertools::sorted fn">sorted</a></td><td class="docblock-short"><p>Sort all iterator elements into a new iterator in ascending order.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.unfold.html" title="itertools::unfold fn">unfold</a></td><td class="docblock-short"><p>Creates a new unfold source with the specified closure as the &quot;iterator
function&quot; and an initial state to eventually pass to the closure</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.zip.html" title="itertools::zip fn">zip</a></td><td class="docblock-short"><p>Iterate <code>i</code> and <code>j</code> in lock step.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.zip_eq.html" title="itertools::zip_eq fn">zip_eq</a></td><td class="docblock-short"><p>Iterate <code>i</code> and <code>j</code> in lock step.</p>
</td></tr></table></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../" data-current-crate="itertools"></div>
<script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>