mirror of
https://github.com/edg-l/edlang.git
synced 2024-11-14 03:58:23 +00:00
2539 lines
501 KiB
HTML
2539 lines
501 KiB
HTML
|
<!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="An `Iterator` blanket implementation that provides extra adaptors and methods."><title>Itertools in itertools - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-ac92e1bbe349e143.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="itertools" data-themes="" data-resource-suffix="" data-rustdoc-version="1.76.0 (07dca489a 2024-02-04)" data-channel="1.76.0" data-search-js="search-2b6ce74ff89ae146.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../static.files/storage-f2adc0d6ca4d09fb.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-305769736d49e732.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-feafe1bb7466e4bd.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc trait"><!--[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">☰</button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../itertools/index.html">itertools</a><span class="version">0.12.1</span></h2></div><h2 class="location"><a href="#">Itertools</a></h2><div class="sidebar-elems"><section><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.all_equal">all_equal</a></li><li><a href="#method.all_equal_value">all_equal_value</a></li><li><a href="#method.all_unique">all_unique</a></li><li><a href="#method.at_most_one">at_most_one</a></li><li><a href="#method.batching">batching</a></li><li><a href="#method.cartesian_product">cartesian_product</a></li><li><a href="#method.chunks">chunks</a></li><li><a href="#method.circular_tuple_windows">circular_tuple_windows</a></li><li><a href="#method.coalesce">coalesce</a></li><li><a href="#method.collect_tuple">collect_tuple</a></li><li><a href="#method.collect_vec">collect_vec</a></li><li><a href="#method.combinations">combinations</a></li><li><a href="#method.combinations_with_replacement">combinations_with_replacement</a></li><li><a href="#method.concat">concat</a></li><li><a href="#method.contains">contains</a></li><li><a href="#method.counts">counts</a></li><li><a href="#method.counts_by">counts_by</a></li><li><a href="#method.dedup">dedup</a></li><li><a href="#method.dedup_by">dedup_by</a></li><li><a href="#method.dedup_by_with_count">dedup_by_with_count</a></li><li><a href="#method.dedup_with_count">dedup_with_count</a></li><li><a href="#method.dropping">dropping</a></li><li><a href="#method.dropping_back">dropping_back</a></li><li><a href="#method.duplicates">duplicates</a></li><li><a href="#method.duplicates_by">duplicates_by</a></li><li><a href="#method.exactly_one">exactly_one</a></li><li><a href="#method.filter_map_ok">filter_map_ok</a></li><li><a href="#metho
|
|||
|
<main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><div id="sidebar-button" tabindex="-1"><a href="../itertools/all.html" title="show sidebar"></a></div><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" tabindex="-1"><a href="../help.html" title="help">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Trait <a href="index.html">itertools</a>::<wbr><a class="trait" href="#">Itertools</a><button id="copy-path" title="Copy item path to clipboard"><img src="../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="src" href="../src/itertools/lib.rs.html#410-3972">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></span></div><pre class="rust item-decl"><code>pub trait Itertools: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a> {
|
|||
|
<details class="toggle type-contents-toggle"><summary class="hideme"><span>Show 116 methods</span></summary> // Provided methods
|
|||
|
fn <a href="#method.interleave" class="fn">interleave</a><J>(self, other: J) -> <a class="struct" href="structs/struct.Interleave.html" title="struct itertools::structs::Interleave">Interleave</a><Self, J::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a>> <a href="#" class="tooltip" data-notable-ty="Interleave<Self, J::IntoIter>">ⓘ</a>
|
|||
|
<span class="where">where J: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a><Item = Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>>,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.interleave_shortest" class="fn">interleave_shortest</a><J>(
|
|||
|
self,
|
|||
|
other: J
|
|||
|
) -> <a class="struct" href="structs/struct.InterleaveShortest.html" title="struct itertools::structs::InterleaveShortest">InterleaveShortest</a><Self, J::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a>> <a href="#" class="tooltip" data-notable-ty="InterleaveShortest<Self, J::IntoIter>">ⓘ</a>
|
|||
|
<span class="where">where J: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a><Item = Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>>,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.intersperse" class="fn">intersperse</a>(self, element: Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="type" href="structs/type.Intersperse.html" title="type itertools::structs::Intersperse">Intersperse</a><Self>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.intersperse_with" class="fn">intersperse_with</a><F>(self, element: F) -> <a class="struct" href="structs/struct.IntersperseWith.html" title="struct itertools::structs::IntersperseWith">IntersperseWith</a><Self, F> <a href="#" class="tooltip" data-notable-ty="IntersperseWith<Self, F>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>() -> Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.zip_longest" class="fn">zip_longest</a><J>(self, other: J) -> <a class="struct" href="structs/struct.ZipLongest.html" title="struct itertools::structs::ZipLongest">ZipLongest</a><Self, J::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a>> <a href="#" class="tooltip" data-notable-ty="ZipLongest<Self, J::IntoIter>">ⓘ</a>
|
|||
|
<span class="where">where J: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.zip_eq" class="fn">zip_eq</a><J>(self, other: J) -> <a class="struct" href="structs/struct.ZipEq.html" title="struct itertools::structs::ZipEq">ZipEq</a><Self, J::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a>> <a href="#" class="tooltip" data-notable-ty="ZipEq<Self, J::IntoIter>">ⓘ</a>
|
|||
|
<span class="where">where J: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.batching" class="fn">batching</a><B, F>(self, f: F) -> <a class="struct" href="structs/struct.Batching.html" title="struct itertools::structs::Batching">Batching</a><Self, F> <a href="#" class="tooltip" data-notable-ty="Batching<Self, F>">ⓘ</a>
|
|||
|
<span class="where">where F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&mut Self</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><B>,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.group_by" class="fn">group_by</a><K, F>(self, key: F) -> <a class="struct" href="structs/struct.GroupBy.html" title="struct itertools::structs::GroupBy">GroupBy</a><K, Self, F>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> K,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.chunks" class="fn">chunks</a>(self, size: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -> <a class="struct" href="structs/struct.IntoChunks.html" title="struct itertools::structs::IntoChunks">IntoChunks</a><Self>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.tuple_windows" class="fn">tuple_windows</a><T>(self) -> <a class="struct" href="structs/struct.TupleWindows.html" title="struct itertools::structs::TupleWindows">TupleWindows</a><Self, T> <a href="#" class="tooltip" data-notable-ty="TupleWindows<Self, T>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = T::Item>,
|
|||
|
T: <a class="trait" href="traits/trait.HomogeneousTuple.html" title="trait itertools::traits::HomogeneousTuple">HomogeneousTuple</a>,
|
|||
|
T::Item: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.circular_tuple_windows" class="fn">circular_tuple_windows</a><T>(self) -> <a class="struct" href="structs/struct.CircularTupleWindows.html" title="struct itertools::structs::CircularTupleWindows">CircularTupleWindows</a><Self, T> <a href="#" class="tooltip" data-notable-ty="CircularTupleWindows<Self, T>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = T::Item> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/exact_size/trait.ExactSizeIterator.html" title="trait core::iter::traits::exact_size::ExactSizeIterator">ExactSizeIterator</a>,
|
|||
|
T: TupleCollect + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,
|
|||
|
T::Item: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.tuples" class="fn">tuples</a><T>(self) -> <a class="struct" href="structs/struct.Tuples.html" title="struct itertools::structs::Tuples">Tuples</a><Self, T> <a href="#" class="tooltip" data-notable-ty="Tuples<Self, T>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = T::Item>,
|
|||
|
T: <a class="trait" href="traits/trait.HomogeneousTuple.html" title="trait itertools::traits::HomogeneousTuple">HomogeneousTuple</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.tee" class="fn">tee</a>(self) -> (<a class="struct" href="structs/struct.Tee.html" title="struct itertools::structs::Tee">Tee</a><Self>, <a class="struct" href="structs/struct.Tee.html" title="struct itertools::structs::Tee">Tee</a><Self>)
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.step" class="fn">step</a>(self, n: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -> <a class="struct" href="structs/struct.Step.html" title="struct itertools::structs::Step">Step</a><Self> <a href="#" class="tooltip" data-notable-ty="Step<Self>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.map_into" class="fn">map_into</a><R>(self) -> <a class="type" href="structs/type.MapInto.html" title="type itertools::structs::MapInto">MapInto</a><Self, R>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><R></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.map_results" class="fn">map_results</a><F, T, U, E>(self, f: F) -> <a class="type" href="structs/type.MapOk.html" title="type itertools::structs::MapOk">MapOk</a><Self, F>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, E>> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(T) -> U</span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.map_ok" class="fn">map_ok</a><F, T, U, E>(self, f: F) -> <a class="type" href="structs/type.MapOk.html" title="type itertools::structs::MapOk">MapOk</a><Self, F>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, E>> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(T) -> U</span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.filter_ok" class="fn">filter_ok</a><F, T, E>(self, f: F) -> <a class="struct" href="structs/struct.FilterOk.html" title="struct itertools::structs::FilterOk">FilterOk</a><Self, F> <a href="#" class="tooltip" data-notable-ty="FilterOk<Self, F>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, E>> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&T</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.filter_map_ok" class="fn">filter_map_ok</a><F, T, U, E>(self, f: F) -> <a class="struct" href="structs/struct.FilterMapOk.html" title="struct itertools::structs::FilterMapOk">FilterMapOk</a><Self, F> <a href="#" class="tooltip" data-notable-ty="FilterMapOk<Self, F>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, E>> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(T) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><U></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.flatten_ok" class="fn">flatten_ok</a><T, E>(self) -> <a class="struct" href="structs/struct.FlattenOk.html" title="struct itertools::structs::FlattenOk">FlattenOk</a><Self, T, E> <a href="#" class="tooltip" data-notable-ty="FlattenOk<Self, T, E>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, E>> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
T: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.process_results" class="fn">process_results</a><F, T, E, R>(self, processor: F) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><R, E>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, E>> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(<a class="struct" href="structs/struct.ProcessResults.html" title="struct itertools::structs::ProcessResults">ProcessResults</a><'_, Self, E>) -> R</span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.merge" class="fn">merge</a><J>(self, other: J) -> <a class="type" href="structs/type.Merge.html" title="type itertools::structs::Merge">Merge</a><Self, J::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a>,
|
|||
|
J: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a><Item = Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.merge_by" class="fn">merge_by</a><J, F>(
|
|||
|
self,
|
|||
|
other: J,
|
|||
|
is_first: F
|
|||
|
) -> <a class="struct" href="structs/struct.MergeBy.html" title="struct itertools::structs::MergeBy">MergeBy</a><Self, J::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a>, F> <a href="#" class="tooltip" data-notable-ty="MergeBy<Self, J::IntoIter, F>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
J: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a><Item = Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, &Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.merge_join_by" class="fn">merge_join_by</a><J, F, T>(
|
|||
|
self,
|
|||
|
other: J,
|
|||
|
cmp_fn: F
|
|||
|
) -> <a class="type" href="structs/type.MergeJoinBy.html" title="type itertools::structs::MergeJoinBy">MergeJoinBy</a><Self, J::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a>, F>
|
|||
|
<span class="where">where J: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, &J::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" title="type core::iter::traits::collect::IntoIterator::Item">Item</a>) -> T,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.kmerge" class="fn">kmerge</a>(self) -> <a class="type" href="structs/type.KMerge.html" title="type itertools::structs::KMerge">KMerge</a><<Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a> as <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,
|
|||
|
<Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a> as <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" title="type core::iter::traits::collect::IntoIterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.kmerge_by" class="fn">kmerge_by</a><F>(
|
|||
|
self,
|
|||
|
first: F
|
|||
|
) -> <a class="struct" href="structs/struct.KMergeBy.html" title="struct itertools::structs::KMergeBy">KMergeBy</a><<Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a> as <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a>, F> <a href="#" class="tooltip" data-notable-ty="KMergeBy<<Self::Item as IntoIterator>::IntoIter, F>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&<Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a> as <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" title="type core::iter::traits::collect::IntoIterator::Item">Item</a>, &<Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a> as <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" title="type core::iter::traits::collect::IntoIterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.cartesian_product" class="fn">cartesian_product</a><J>(self, other: J) -> <a class="struct" href="structs/struct.Product.html" title="struct itertools::structs::Product">Product</a><Self, J::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a>> <a href="#" class="tooltip" data-notable-ty="Product<Self, J::IntoIter>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,
|
|||
|
J: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,
|
|||
|
J::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.multi_cartesian_product" class="fn">multi_cartesian_product</a>(
|
|||
|
self
|
|||
|
) -> <a class="struct" href="structs/struct.MultiProduct.html" title="struct itertools::structs::MultiProduct">MultiProduct</a><<Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a> as <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a>> <a href="#" class="tooltip" data-notable-ty="MultiProduct<<Self::Item as IntoIterator>::IntoIter>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,
|
|||
|
<Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a> as <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,
|
|||
|
<Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a> as <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" title="type core::iter::traits::collect::IntoIterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.coalesce" class="fn">coalesce</a><F>(self, f: F) -> <a class="type" href="structs/type.Coalesce.html" title="type itertools::structs::Coalesce">Coalesce</a><Self, F>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, (Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>)></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.dedup" class="fn">dedup</a>(self) -> <a class="type" href="structs/type.Dedup.html" title="type itertools::structs::Dedup">Dedup</a><Self>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.dedup_by" class="fn">dedup_by</a><Cmp>(self, cmp: Cmp) -> <a class="type" href="structs/type.DedupBy.html" title="type itertools::structs::DedupBy">DedupBy</a><Self, Cmp>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Cmp: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, &Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.dedup_with_count" class="fn">dedup_with_count</a>(self) -> <a class="type" href="structs/type.DedupWithCount.html" title="type itertools::structs::DedupWithCount">DedupWithCount</a><Self>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.dedup_by_with_count" class="fn">dedup_by_with_count</a><Cmp>(self, cmp: Cmp) -> <a class="type" href="structs/type.DedupByWithCount.html" title="type itertools::structs::DedupByWithCount">DedupByWithCount</a><Self, Cmp>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Cmp: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, &Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.duplicates" class="fn">duplicates</a>(self) -> <a class="type" href="structs/type.Duplicates.html" title="type itertools::structs::Duplicates">Duplicates</a><Self>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.duplicates_by" class="fn">duplicates_by</a><V, F>(self, f: F) -> <a class="type" href="structs/type.DuplicatesBy.html" title="type itertools::structs::DuplicatesBy">DuplicatesBy</a><Self, V, F>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
V: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> V</span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.unique" class="fn">unique</a>(self) -> <a class="struct" href="structs/struct.Unique.html" title="struct itertools::structs::Unique">Unique</a><Self> <a href="#" class="tooltip" data-notable-ty="Unique<Self>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.unique_by" class="fn">unique_by</a><V, F>(self, f: F) -> <a class="struct" href="structs/struct.UniqueBy.html" title="struct itertools::structs::UniqueBy">UniqueBy</a><Self, V, F> <a href="#" class="tooltip" data-notable-ty="UniqueBy<Self, V, F>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
V: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> V</span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.peeking_take_while" class="fn">peeking_take_while</a><F>(
|
|||
|
&mut self,
|
|||
|
accept: F
|
|||
|
) -> <a class="struct" href="structs/struct.PeekingTakeWhile.html" title="struct itertools::structs::PeekingTakeWhile">PeekingTakeWhile</a><'_, Self, F> <a href="#" class="tooltip" data-notable-ty="PeekingTakeWhile<'_, Self, F>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="trait.PeekingNext.html" title="trait itertools::PeekingNext">PeekingNext</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.take_while_ref" class="fn">take_while_ref</a><F>(&mut self, accept: F) -> <a class="struct" href="structs/struct.TakeWhileRef.html" title="struct itertools::structs::TakeWhileRef">TakeWhileRef</a><'_, Self, F> <a href="#" class="tooltip" data-notable-ty="TakeWhileRef<'_, Self, F>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.take_while_inclusive" class="fn">take_while_inclusive</a><F>(self, accept: F) -> <a class="struct" href="structs/struct.TakeWhileInclusive.html" title="struct itertools::structs::TakeWhileInclusive">TakeWhileInclusive</a><Self, F> <a href="#" class="tooltip" data-notable-ty="TakeWhileInclusive<Self, F>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.while_some" class="fn">while_some</a><A>(self) -> <a class="struct" href="structs/struct.WhileSome.html" title="struct itertools::structs::WhileSome">WhileSome</a><Self> <a href="#" class="tooltip" data-notable-ty="WhileSome<Self>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><A>></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.tuple_combinations" class="fn">tuple_combinations</a><T>(self) -> <a class="struct" href="structs/struct.TupleCombinations.html" title="struct itertools::structs::TupleCombinations">TupleCombinations</a><Self, T> <a href="#" class="tooltip" data-notable-ty="TupleCombinations<Self, T>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,
|
|||
|
T: HasCombination<Self></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.combinations" class="fn">combinations</a>(self, k: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -> <a class="struct" href="structs/struct.Combinations.html" title="struct itertools::structs::Combinations">Combinations</a><Self> <a href="#" class="tooltip" data-notable-ty="Combinations<Self>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.combinations_with_replacement" class="fn">combinations_with_replacement</a>(
|
|||
|
self,
|
|||
|
k: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>
|
|||
|
) -> <a class="struct" href="structs/struct.CombinationsWithReplacement.html" title="struct itertools::structs::CombinationsWithReplacement">CombinationsWithReplacement</a><Self> <a href="#" class="tooltip" data-notable-ty="CombinationsWithReplacement<Self>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.permutations" class="fn">permutations</a>(self, k: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -> <a class="struct" href="structs/struct.Permutations.html" title="struct itertools::structs::Permutations">Permutations</a><Self> <a href="#" class="tooltip" data-notable-ty="Permutations<Self>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.powerset" class="fn">powerset</a>(self) -> <a class="struct" href="structs/struct.Powerset.html" title="struct itertools::structs::Powerset">Powerset</a><Self> <a href="#" class="tooltip" data-notable-ty="Powerset<Self>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.pad_using" class="fn">pad_using</a><F>(self, min: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>, f: F) -> <a class="struct" href="structs/struct.PadUsing.html" title="struct itertools::structs::PadUsing">PadUsing</a><Self, F> <a href="#" class="tooltip" data-notable-ty="PadUsing<Self, F>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -> Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.with_position" class="fn">with_position</a>(self) -> <a class="struct" href="structs/struct.WithPosition.html" title="struct itertools::structs::WithPosition">WithPosition</a><Self> <a href="#" class="tooltip" data-notable-ty="WithPosition<Self>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.positions" class="fn">positions</a><P>(self, predicate: P) -> <a class="struct" href="structs/struct.Positions.html" title="struct itertools::structs::Positions">Positions</a><Self, P> <a href="#" class="tooltip" data-notable-ty="Positions<Self, P>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
P: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.update" class="fn">update</a><F>(self, updater: F) -> <a class="struct" href="structs/struct.Update.html" title="struct itertools::structs::Update">Update</a><Self, F> <a href="#" class="tooltip" data-notable-ty="Update<Self, F>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&mut Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>)</span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.next_tuple" class="fn">next_tuple</a><T>(&mut self) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><T>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = T::Item>,
|
|||
|
T: <a class="trait" href="traits/trait.HomogeneousTuple.html" title="trait itertools::traits::HomogeneousTuple">HomogeneousTuple</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.collect_tuple" class="fn">collect_tuple</a><T>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><T>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = T::Item>,
|
|||
|
T: <a class="trait" href="traits/trait.HomogeneousTuple.html" title="trait itertools::traits::HomogeneousTuple">HomogeneousTuple</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.find_position" class="fn">find_position</a><P>(&mut self, pred: P) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><(<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>, Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>)>
|
|||
|
<span class="where">where P: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.find_or_last" class="fn">find_or_last</a><P>(self, predicate: P) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
P: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.find_or_first" class="fn">find_or_first</a><P>(self, predicate: P) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
P: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.contains" class="fn">contains</a><Q>(&mut self, query: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&Q</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><Q>,
|
|||
|
Q: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.all_equal" class="fn">all_equal</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.all_equal_value" class="fn">all_equal_value</a>(
|
|||
|
&mut self
|
|||
|
) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><(Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>)>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.all_unique" class="fn">all_unique</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.dropping" class="fn">dropping</a>(self, n: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -> Self
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.dropping_back" class="fn">dropping_back</a>(self, n: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -> Self
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/double_ended/trait.DoubleEndedIterator.html" title="trait core::iter::traits::double_ended::DoubleEndedIterator">DoubleEndedIterator</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.foreach" class="fn">foreach</a><F>(self, f: F)
|
|||
|
<span class="where">where F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>),
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.concat" class="fn">concat</a>(self) -> Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.Extend.html" title="trait core::iter::traits::collect::Extend">Extend</a><<<Self as <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a> as <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" title="type core::iter::traits::collect::IntoIterator::Item">Item</a>> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/default/trait.Default.html" title="trait core::default::Default">Default</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.collect_vec" class="fn">collect_vec</a>(self) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.try_collect" class="fn">try_collect</a><T, U, E>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><U, E>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, E>>,
|
|||
|
<a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><U, E>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.FromIterator.html" title="trait core::iter::traits::collect::FromIterator">FromIterator</a><<a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, E>></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.set_from" class="fn">set_from</a><'a, A: 'a, J>(&mut self, from: J) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&'a mut A</a>>,
|
|||
|
J: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a><Item = A></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.join" class="fn">join</a>(&mut self, sep: &<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.str.html">str</a>) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>
|
|||
|
<span class="where">where Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.format" class="fn">format</a>(self, sep: &<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.str.html">str</a>) -> <a class="struct" href="structs/struct.Format.html" title="struct itertools::structs::Format">Format</a><'_, Self>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.format_with" class="fn">format_with</a><F>(self, sep: &<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.str.html">str</a>, format: F) -> <a class="struct" href="structs/struct.FormatWith.html" title="struct itertools::structs::FormatWith">FormatWith</a><'_, Self, F>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, &mut dyn <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&dyn <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a>) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a>) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.fold_results" class="fn">fold_results</a><A, E, B, F>(&mut self, start: B, f: F) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><B, E>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><A, E>>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(B, A) -> B</span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.fold_ok" class="fn">fold_ok</a><A, E, B, F>(&mut self, start: B, f: F) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><B, E>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><A, E>>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(B, A) -> B</span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.fold_options" class="fn">fold_options</a><A, B, F>(&mut self, start: B, f: F) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><B>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><A>>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(B, A) -> B</span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.fold1" class="fn">fold1</a><F>(self, f: F) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>>
|
|||
|
<span class="where">where F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.tree_fold1" class="fn">tree_fold1</a><F>(self, f: F) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>>
|
|||
|
<span class="where">where F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.fold_while" class="fn">fold_while</a><B, F>(&mut self, init: B, f: F) -> <a class="enum" href="enum.FoldWhile.html" title="enum itertools::FoldWhile">FoldWhile</a><B>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(B, Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="enum" href="enum.FoldWhile.html" title="enum itertools::FoldWhile">FoldWhile</a><B></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.sum1" class="fn">sum1</a><S>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><S>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
S: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/accum/trait.Sum.html" title="trait core::iter::traits::accum::Sum">Sum</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.product1" class="fn">product1</a><P>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><P>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
P: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/accum/trait.Product.html" title="trait core::iter::traits::accum::Product">Product</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.sorted_unstable" class="fn">sorted_unstable</a>(self) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/into_iter/struct.IntoIter.html" title="struct alloc::vec::into_iter::IntoIter">IntoIter</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>> <a href="#" class="tooltip" data-notable-ty="IntoIter<Self::Item>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.sorted_unstable_by" class="fn">sorted_unstable_by</a><F>(self, cmp: F) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/into_iter/struct.IntoIter.html" title="struct alloc::vec::into_iter::IntoIter">IntoIter</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>> <a href="#" class="tooltip" data-notable-ty="IntoIter<Self::Item>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, &Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.sorted_unstable_by_key" class="fn">sorted_unstable_by_key</a><K, F>(self, f: F) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/into_iter/struct.IntoIter.html" title="struct alloc::vec::into_iter::IntoIter">IntoIter</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>> <a href="#" class="tooltip" data-notable-ty="IntoIter<Self::Item>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> K</span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.sorted" class="fn">sorted</a>(self) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/into_iter/struct.IntoIter.html" title="struct alloc::vec::into_iter::IntoIter">IntoIter</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>> <a href="#" class="tooltip" data-notable-ty="IntoIter<Self::Item>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.sorted_by" class="fn">sorted_by</a><F>(self, cmp: F) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/into_iter/struct.IntoIter.html" title="struct alloc::vec::into_iter::IntoIter">IntoIter</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>> <a href="#" class="tooltip" data-notable-ty="IntoIter<Self::Item>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, &Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.sorted_by_key" class="fn">sorted_by_key</a><K, F>(self, f: F) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/into_iter/struct.IntoIter.html" title="struct alloc::vec::into_iter::IntoIter">IntoIter</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>> <a href="#" class="tooltip" data-notable-ty="IntoIter<Self::Item>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> K</span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.sorted_by_cached_key" class="fn">sorted_by_cached_key</a><K, F>(self, f: F) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/into_iter/struct.IntoIter.html" title="struct alloc::vec::into_iter::IntoIter">IntoIter</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>> <a href="#" class="tooltip" data-notable-ty="IntoIter<Self::Item>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> K</span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.k_smallest" class="fn">k_smallest</a>(self, k: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/into_iter/struct.IntoIter.html" title="struct alloc::vec::into_iter::IntoIter">IntoIter</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>> <a href="#" class="tooltip" data-notable-ty="IntoIter<Self::Item>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.partition_map" class="fn">partition_map</a><A, B, F, L, R>(self, predicate: F) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.tuple.html">(A, B)</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="enum" href="enum.Either.html" title="enum itertools::Either">Either</a><L, R>,
|
|||
|
A: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/default/trait.Default.html" title="trait core::default::Default">Default</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.Extend.html" title="trait core::iter::traits::collect::Extend">Extend</a><L>,
|
|||
|
B: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/default/trait.Default.html" title="trait core::default::Default">Default</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.Extend.html" title="trait core::iter::traits::collect::Extend">Extend</a><R></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.partition_result" class="fn">partition_result</a><A, B, T, E>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.tuple.html">(A, B)</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, E>> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
A: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/default/trait.Default.html" title="trait core::default::Default">Default</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.Extend.html" title="trait core::iter::traits::collect::Extend">Extend</a><T>,
|
|||
|
B: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/default/trait.Default.html" title="trait core::default::Default">Default</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.Extend.html" title="trait core::iter::traits::collect::Extend">Extend</a><E></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.into_group_map" class="fn">into_group_map</a><K, V>(self) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/collections/hash/map/struct.HashMap.html" title="struct std::collections::hash::map::HashMap">HashMap</a><K, <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><V>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.tuple.html">(K, V)</a>> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.into_group_map_by" class="fn">into_group_map_by</a><K, V, F>(self, f: F) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/collections/hash/map/struct.HashMap.html" title="struct std::collections::hash::map::HashMap">HashMap</a><K, <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><V>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = V> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&V</a>) -> K</span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.into_grouping_map" class="fn">into_grouping_map</a><K, V>(self) -> <a class="struct" href="structs/struct.GroupingMap.html" title="struct itertools::structs::GroupingMap">GroupingMap</a><Self>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.tuple.html">(K, V)</a>> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.into_grouping_map_by" class="fn">into_grouping_map_by</a><K, V, F>(
|
|||
|
self,
|
|||
|
key_mapper: F
|
|||
|
) -> <a class="type" href="structs/type.GroupingMapBy.html" title="type itertools::structs::GroupingMapBy">GroupingMapBy</a><Self, F>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = V> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&V</a>) -> K</span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.min_set" class="fn">min_set</a>(self) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.min_set_by" class="fn">min_set_by</a><F>(self, compare: F) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, &Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.min_set_by_key" class="fn">min_set_by_key</a><K, F>(self, key: F) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> K</span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.max_set" class="fn">max_set</a>(self) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.max_set_by" class="fn">max_set_by</a><F>(self, compare: F) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, &Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.max_set_by_key" class="fn">max_set_by_key</a><K, F>(self, key: F) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> K</span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.minmax" class="fn">minmax</a>(self) -> <a class="enum" href="enum.MinMaxResult.html" title="enum itertools::MinMaxResult">MinMaxResult</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.minmax_by_key" class="fn">minmax_by_key</a><K, F>(self, key: F) -> <a class="enum" href="enum.MinMaxResult.html" title="enum itertools::MinMaxResult">MinMaxResult</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> K</span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.minmax_by" class="fn">minmax_by</a><F>(self, compare: F) -> <a class="enum" href="enum.MinMaxResult.html" title="enum itertools::MinMaxResult">MinMaxResult</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, &Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.position_max" class="fn">position_max</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.position_max_by_key" class="fn">position_max_by_key</a><K, F>(self, key: F) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> K</span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.position_max_by" class="fn">position_max_by</a><F>(self, compare: F) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, &Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.position_min" class="fn">position_min</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.position_min_by_key" class="fn">position_min_by_key</a><K, F>(self, key: F) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> K</span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.position_min_by" class="fn">position_min_by</a><F>(self, compare: F) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, &Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.position_minmax" class="fn">position_minmax</a>(self) -> <a class="enum" href="enum.MinMaxResult.html" title="enum itertools::MinMaxResult">MinMaxResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.position_minmax_by_key" class="fn">position_minmax_by_key</a><K, F>(self, key: F) -> <a class="enum" href="enum.MinMaxResult.html" title="enum itertools::MinMaxResult">MinMaxResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> K</span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.position_minmax_by" class="fn">position_minmax_by</a><F>(self, compare: F) -> <a class="enum" href="enum.MinMaxResult.html" title="enum itertools::MinMaxResult">MinMaxResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, &Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.exactly_one" class="fn">exactly_one</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, <a class="struct" href="structs/struct.ExactlyOneError.html" title="struct itertools::structs::ExactlyOneError">ExactlyOneError</a><Self>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.at_most_one" class="fn">at_most_one</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>>, <a class="struct" href="structs/struct.ExactlyOneError.html" title="struct itertools::structs::ExactlyOneError">ExactlyOneError</a><Self>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.multipeek" class="fn">multipeek</a>(self) -> <a class="struct" href="structs/struct.MultiPeek.html" title="struct itertools::structs::MultiPeek">MultiPeek</a><Self> <a href="#" class="tooltip" data-notable-ty="MultiPeek<Self>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.counts" class="fn">counts</a>(self) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/collections/hash/map/struct.HashMap.html" title="struct std::collections::hash::map::HashMap">HashMap</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.counts_by" class="fn">counts_by</a><K, F>(self, f: F) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/collections/hash/map/struct.HashMap.html" title="struct std::collections::hash::map::HashMap">HashMap</a><K, <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> K</span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.multiunzip" class="fn">multiunzip</a><FromI>(self) -> FromI
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="trait.MultiUnzip.html" title="trait itertools::MultiUnzip">MultiUnzip</a><FromI></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.try_len" class="fn">try_len</a>(&self) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>, (<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>, <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>>)> { ... }
|
|||
|
</details>}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>An <a href="https://doc.rust-lang.org/1.76.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.</p>
|
|||
|
<p>This trait defines a number of methods. They are divided into two groups:</p>
|
|||
|
<ul>
|
|||
|
<li>
|
|||
|
<p><em>Adaptors</em> take an iterator and parameter as input, and return
|
|||
|
a new iterator value. These are listed first in the trait. An example
|
|||
|
of an adaptor is <a href="trait.Itertools.html#method.interleave" title="method itertools::Itertools::interleave"><code>.interleave()</code></a></p>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<p><em>Regular methods</em> are those that don’t return iterators and instead
|
|||
|
return a regular value of some other kind.
|
|||
|
<a href="trait.Itertools.html#method.next_tuple" title="method itertools::Itertools::next_tuple"><code>.next_tuple()</code></a> is an example and the first regular
|
|||
|
method in the list.</p>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
</div></details><h2 id="provided-methods" class="section-header">Provided Methods<a href="#provided-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="method.interleave" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#425-431">source</a><h4 class="code-header">fn <a href="#method.interleave" class="fn">interleave</a><J>(self, other: J) -> <a class="struct" href="structs/struct.Interleave.html" title="struct itertools::structs::Interleave">Interleave</a><Self, J::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a>> <a href="#" class="tooltip" data-notable-ty="Interleave<Self, J::IntoIter>">ⓘ</a><div class="where">where
|
|||
|
J: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a><Item = Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>>,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Alternate elements from two iterators until both have run out.</p>
|
|||
|
<p>Iterator element type is <code>Self::Item</code>.</p>
|
|||
|
<p>This iterator is <em>fused</em>.</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">7</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>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.interleave_shortest" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#444-450">source</a><h4 class="code-header">fn <a href="#method.interleave_shortest" class="fn">interleave_shortest</a><J>(
|
|||
|
self,
|
|||
|
other: J
|
|||
|
) -> <a class="struct" href="structs/struct.InterleaveShortest.html" title="struct itertools::structs::InterleaveShortest">InterleaveShortest</a><Self, J::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a>> <a href="#" class="tooltip" data-notable-ty="InterleaveShortest<Self, J::IntoIter>">ⓘ</a><div class="where">where
|
|||
|
J: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a><Item = Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>>,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Alternate elements from two iterators until at least one of them has run
|
|||
|
out.</p>
|
|||
|
<p>Iterator element type is <code>Self::Item</code>.</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">7</span>).interleave_shortest(<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>, <span class="number">3</span>]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.intersperse" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#464-470">source</a><h4 class="code-header">fn <a href="#method.intersperse" class="fn">intersperse</a>(self, element: Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="type" href="structs/type.Intersperse.html" title="type itertools::structs::Intersperse">Intersperse</a><Self><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,</div></h4></section></summary><div class="docblock"><p>An iterator adaptor to insert a particular value
|
|||
|
between each element of the adapted iterator.</p>
|
|||
|
<p>Iterator element type is <code>Self::Item</code>.</p>
|
|||
|
<p>This iterator is <em>fused</em>.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
itertools::assert_equal((<span class="number">0</span>..<span class="number">3</span>).intersperse(<span class="number">8</span>), <span class="macro">vec!</span>[<span class="number">0</span>, <span class="number">8</span>, <span class="number">1</span>, <span class="number">8</span>, <span class="number">2</span>]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.intersperse_with" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#486-492">source</a><h4 class="code-header">fn <a href="#method.intersperse_with" class="fn">intersperse_with</a><F>(self, element: F) -> <a class="struct" href="structs/struct.IntersperseWith.html" title="struct itertools::structs::IntersperseWith">IntersperseWith</a><Self, F> <a href="#" class="tooltip" data-notable-ty="IntersperseWith<Self, F>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>() -> Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>,</div></h4></section></summary><div class="docblock"><p>An iterator adaptor to insert a particular value created by a function
|
|||
|
between each element of the adapted iterator.</p>
|
|||
|
<p>Iterator element type is <code>Self::Item</code>.</p>
|
|||
|
<p>This iterator is <em>fused</em>.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span><span class="kw-2">mut </span>i = <span class="number">10</span>;
|
|||
|
itertools::assert_equal((<span class="number">0</span>..<span class="number">3</span>).intersperse_with(|| { i -= <span class="number">1</span>; i }), <span class="macro">vec!</span>[<span class="number">0</span>, <span class="number">9</span>, <span class="number">1</span>, <span class="number">8</span>, <span class="number">2</span>]);
|
|||
|
<span class="macro">assert_eq!</span>(i, <span class="number">8</span>);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.zip_longest" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#521-527">source</a><h4 class="code-header">fn <a href="#method.zip_longest" class="fn">zip_longest</a><J>(self, other: J) -> <a class="struct" href="structs/struct.ZipLongest.html" title="struct itertools::structs::ZipLongest">ZipLongest</a><Self, J::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a>> <a href="#" class="tooltip" data-notable-ty="ZipLongest<Self, J::IntoIter>">ⓘ</a><div class="where">where
|
|||
|
J: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Create an iterator which iterates over both this and the specified
|
|||
|
iterator simultaneously, yielding pairs of two optional elements.</p>
|
|||
|
<p>This iterator is <em>fused</em>.</p>
|
|||
|
<p>As long as neither input iterator is exhausted yet, it yields two values
|
|||
|
via <code>EitherOrBoth::Both</code>.</p>
|
|||
|
<p>When the parameter iterator is exhausted, it only yields a value from the
|
|||
|
<code>self</code> iterator via <code>EitherOrBoth::Left</code>.</p>
|
|||
|
<p>When the <code>self</code> iterator is exhausted, it only yields a value from the
|
|||
|
parameter iterator via <code>EitherOrBoth::Right</code>.</p>
|
|||
|
<p>When both iterators return <code>None</code>, all further invocations of <code>.next()</code>
|
|||
|
will return <code>None</code>.</p>
|
|||
|
<p>Iterator element type is
|
|||
|
<a href="enum.EitherOrBoth.html" title="enum itertools::EitherOrBoth"><code>EitherOrBoth<Self::Item, J::Item></code></a>.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::EitherOrBoth::{Both, Right};
|
|||
|
<span class="kw">use </span>itertools::Itertools;
|
|||
|
<span class="kw">let </span>it = (<span class="number">0</span>..<span class="number">1</span>).zip_longest(<span class="number">1</span>..<span class="number">3</span>);
|
|||
|
itertools::assert_equal(it, <span class="macro">vec!</span>[Both(<span class="number">0</span>, <span class="number">1</span>), Right(<span class="number">2</span>)]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.zip_eq" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#535-541">source</a><h4 class="code-header">fn <a href="#method.zip_eq" class="fn">zip_eq</a><J>(self, other: J) -> <a class="struct" href="structs/struct.ZipEq.html" title="struct itertools::structs::ZipEq">ZipEq</a><Self, J::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a>> <a href="#" class="tooltip" data-notable-ty="ZipEq<Self, J::IntoIter>">ⓘ</a><div class="where">where
|
|||
|
J: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Create an iterator which iterates over both this and the specified
|
|||
|
iterator simultaneously, yielding pairs of elements.</p>
|
|||
|
<p><strong>Panics</strong> if the iterators reach an end and they are not of equal
|
|||
|
lengths.</p>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.batching" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#566-572">source</a><h4 class="code-header">fn <a href="#method.batching" class="fn">batching</a><B, F>(self, f: F) -> <a class="struct" href="structs/struct.Batching.html" title="struct itertools::structs::Batching">Batching</a><Self, F> <a href="#" class="tooltip" data-notable-ty="Batching<Self, F>">ⓘ</a><div class="where">where
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&mut Self</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><B>,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>A “meta iterator adaptor”. Its closure receives a reference to the
|
|||
|
iterator and may pick off as many elements as it likes, to produce the
|
|||
|
next iterator element.</p>
|
|||
|
<p>Iterator element type is <code>B</code>.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="comment">// An adaptor that gathers elements in pairs
|
|||
|
</span><span class="kw">let </span>pit = (<span class="number">0</span>..<span class="number">4</span>).batching(|it| {
|
|||
|
<span class="kw">match </span>it.next() {
|
|||
|
<span class="prelude-val">None </span>=> <span class="prelude-val">None</span>,
|
|||
|
<span class="prelude-val">Some</span>(x) => <span class="kw">match </span>it.next() {
|
|||
|
<span class="prelude-val">None </span>=> <span class="prelude-val">None</span>,
|
|||
|
<span class="prelude-val">Some</span>(y) => <span class="prelude-val">Some</span>((x, y)),
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
itertools::assert_equal(pit, <span class="macro">vec!</span>[(<span class="number">0</span>, <span class="number">1</span>), (<span class="number">2</span>, <span class="number">3</span>)]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.group_by" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#609-616">source</a><h4 class="code-header">fn <a href="#method.group_by" class="fn">group_by</a><K, F>(self, key: F) -> <a class="struct" href="structs/struct.GroupBy.html" title="struct itertools::structs::GroupBy">GroupBy</a><K, Self, F><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> K,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a>,</div></h4></section></summary><div class="docblock"><p>Return an <em>iterable</em> that can group iterator elements.
|
|||
|
Consecutive elements that map to the same key (“runs”), are assigned
|
|||
|
to the same group.</p>
|
|||
|
<p><code>GroupBy</code> is the storage for the lazy grouping operation.</p>
|
|||
|
<p>If the groups are consumed in order, or if each group’s iterator is
|
|||
|
dropped without keeping it around, then <code>GroupBy</code> uses no
|
|||
|
allocations. It needs allocations only if several group iterators
|
|||
|
are alive at the same time.</p>
|
|||
|
<p>This type implements <a href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator"><code>IntoIterator</code></a> (it is <strong>not</strong> an iterator
|
|||
|
itself), because the group iterators need to borrow from this
|
|||
|
value. It should be stored in a local variable or temporary and
|
|||
|
iterated.</p>
|
|||
|
<p>Iterator element type is <code>(K, Group)</code>: the group’s key and the
|
|||
|
group iterator.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="comment">// group data into runs of larger than zero or not.
|
|||
|
</span><span class="kw">let </span>data = <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">3</span>, -<span class="number">2</span>, -<span class="number">2</span>, <span class="number">1</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>];
|
|||
|
<span class="comment">// groups: |---->|------>|--------->|
|
|||
|
|
|||
|
// Note: The `&` is significant here, `GroupBy` is iterable
|
|||
|
// only by reference. You can also call `.into_iter()` explicitly.
|
|||
|
</span><span class="kw">let </span><span class="kw-2">mut </span>data_grouped = Vec::new();
|
|||
|
<span class="kw">for </span>(key, group) <span class="kw">in </span><span class="kw-2">&</span>data.into_iter().group_by(|elt| <span class="kw-2">*</span>elt >= <span class="number">0</span>) {
|
|||
|
data_grouped.push((key, group.collect()));
|
|||
|
}
|
|||
|
<span class="macro">assert_eq!</span>(data_grouped, <span class="macro">vec!</span>[(<span class="bool-val">true</span>, <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">3</span>]), (<span class="bool-val">false</span>, <span class="macro">vec!</span>[-<span class="number">2</span>, -<span class="number">2</span>]), (<span class="bool-val">true</span>, <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>])]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.chunks" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#646-652">source</a><h4 class="code-header">fn <a href="#method.chunks" class="fn">chunks</a>(self, size: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -> <a class="struct" href="structs/struct.IntoChunks.html" title="struct itertools::structs::IntoChunks">IntoChunks</a><Self><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Return an <em>iterable</em> that can chunk the iterator.</p>
|
|||
|
<p>Yield subiterators (chunks) that each yield a fixed number elements,
|
|||
|
determined by <code>size</code>. The last chunk will be shorter if there aren’t
|
|||
|
enough elements.</p>
|
|||
|
<p><code>IntoChunks</code> is based on <code>GroupBy</code>: it is iterable (implements
|
|||
|
<code>IntoIterator</code>, <strong>not</strong> <code>Iterator</code>), and it only buffers if several
|
|||
|
chunk iterators are alive at the same time.</p>
|
|||
|
<p>Iterator element type is <code>Chunk</code>, each chunk’s iterator.</p>
|
|||
|
<p><strong>Panics</strong> if <code>size</code> is 0.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>data = <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>, <span class="number">6</span>, <span class="number">0</span>, <span class="number">3</span>, <span class="number">1</span>];
|
|||
|
<span class="comment">//chunk size=3 |------->|-------->|--->|
|
|||
|
|
|||
|
// Note: The `&` is significant here, `IntoChunks` is iterable
|
|||
|
// only by reference. You can also call `.into_iter()` explicitly.
|
|||
|
</span><span class="kw">for </span>chunk <span class="kw">in </span><span class="kw-2">&</span>data.into_iter().chunks(<span class="number">3</span>) {
|
|||
|
<span class="comment">// Check that the sum of each chunk is 4.
|
|||
|
</span><span class="macro">assert_eq!</span>(<span class="number">4</span>, chunk.sum());
|
|||
|
}</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.tuple_windows" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#687-694">source</a><h4 class="code-header">fn <a href="#method.tuple_windows" class="fn">tuple_windows</a><T>(self) -> <a class="struct" href="structs/struct.TupleWindows.html" title="struct itertools::structs::TupleWindows">TupleWindows</a><Self, T> <a href="#" class="tooltip" data-notable-ty="TupleWindows<Self, T>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = T::Item>,
|
|||
|
T: <a class="trait" href="traits/trait.HomogeneousTuple.html" title="trait itertools::traits::HomogeneousTuple">HomogeneousTuple</a>,
|
|||
|
T::Item: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,</div></h4></section></summary><div class="docblock"><p>Return an iterator over all contiguous windows producing tuples of
|
|||
|
a specific size (up to 12).</p>
|
|||
|
<p><code>tuple_windows</code> clones the iterator elements so that they can be
|
|||
|
part of successive windows, this makes it most suited for iterators
|
|||
|
of references and other values that are cheap to copy.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
<span class="kw">let </span><span class="kw-2">mut </span>v = Vec::new();
|
|||
|
|
|||
|
<span class="comment">// pairwise iteration
|
|||
|
</span><span class="kw">for </span>(a, b) <span class="kw">in </span>(<span class="number">1</span>..<span class="number">5</span>).tuple_windows() {
|
|||
|
v.push((a, b));
|
|||
|
}
|
|||
|
<span class="macro">assert_eq!</span>(v, <span class="macro">vec!</span>[(<span class="number">1</span>, <span class="number">2</span>), (<span class="number">2</span>, <span class="number">3</span>), (<span class="number">3</span>, <span class="number">4</span>)]);
|
|||
|
|
|||
|
<span class="kw">let </span><span class="kw-2">mut </span>it = (<span class="number">1</span>..<span class="number">5</span>).tuple_windows();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>((<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>)), it.next());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>((<span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>)), it.next());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, it.next());
|
|||
|
|
|||
|
<span class="comment">// this requires a type hint
|
|||
|
</span><span class="kw">let </span>it = (<span class="number">1</span>..<span class="number">5</span>).tuple_windows::<(<span class="kw">_</span>, <span class="kw">_</span>, <span class="kw">_</span>)>();
|
|||
|
itertools::assert_equal(it, <span class="macro">vec!</span>[(<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>), (<span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>)]);
|
|||
|
|
|||
|
<span class="comment">// you can also specify the complete type
|
|||
|
</span><span class="kw">use </span>itertools::TupleWindows;
|
|||
|
<span class="kw">use </span>std::ops::Range;
|
|||
|
|
|||
|
<span class="kw">let </span>it: TupleWindows<Range<u32>, (u32, u32, u32)> = (<span class="number">1</span>..<span class="number">5</span>).tuple_windows();
|
|||
|
itertools::assert_equal(it, <span class="macro">vec!</span>[(<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>), (<span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>)]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.circular_tuple_windows" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#723-730">source</a><h4 class="code-header">fn <a href="#method.circular_tuple_windows" class="fn">circular_tuple_windows</a><T>(self) -> <a class="struct" href="structs/struct.CircularTupleWindows.html" title="struct itertools::structs::CircularTupleWindows">CircularTupleWindows</a><Self, T> <a href="#" class="tooltip" data-notable-ty="CircularTupleWindows<Self, T>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = T::Item> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/exact_size/trait.ExactSizeIterator.html" title="trait core::iter::traits::exact_size::ExactSizeIterator">ExactSizeIterator</a>,
|
|||
|
T: TupleCollect + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,
|
|||
|
T::Item: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,</div></h4></section></summary><div class="docblock"><p>Return an iterator over all windows, wrapping back to the first
|
|||
|
elements when the window would otherwise exceed the length of the
|
|||
|
iterator, producing tuples of a specific size (up to 12).</p>
|
|||
|
<p><code>circular_tuple_windows</code> clones the iterator elements so that they can be
|
|||
|
part of successive windows, this makes it most suited for iterators
|
|||
|
of references and other values that are cheap to copy.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
<span class="kw">let </span><span class="kw-2">mut </span>v = Vec::new();
|
|||
|
<span class="kw">for </span>(a, b) <span class="kw">in </span>(<span class="number">1</span>..<span class="number">5</span>).circular_tuple_windows() {
|
|||
|
v.push((a, b));
|
|||
|
}
|
|||
|
<span class="macro">assert_eq!</span>(v, <span class="macro">vec!</span>[(<span class="number">1</span>, <span class="number">2</span>), (<span class="number">2</span>, <span class="number">3</span>), (<span class="number">3</span>, <span class="number">4</span>), (<span class="number">4</span>, <span class="number">1</span>)]);
|
|||
|
|
|||
|
<span class="kw">let </span><span class="kw-2">mut </span>it = (<span class="number">1</span>..<span class="number">5</span>).circular_tuple_windows();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>((<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>)), it.next());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>((<span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>)), it.next());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>((<span class="number">3</span>, <span class="number">4</span>, <span class="number">1</span>)), it.next());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>((<span class="number">4</span>, <span class="number">1</span>, <span class="number">2</span>)), it.next());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, it.next());
|
|||
|
|
|||
|
<span class="comment">// this requires a type hint
|
|||
|
</span><span class="kw">let </span>it = (<span class="number">1</span>..<span class="number">5</span>).circular_tuple_windows::<(<span class="kw">_</span>, <span class="kw">_</span>, <span class="kw">_</span>)>();
|
|||
|
itertools::assert_equal(it, <span class="macro">vec!</span>[(<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>), (<span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>), (<span class="number">3</span>, <span class="number">4</span>, <span class="number">1</span>), (<span class="number">4</span>, <span class="number">1</span>, <span class="number">2</span>)]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.tuples" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#762-768">source</a><h4 class="code-header">fn <a href="#method.tuples" class="fn">tuples</a><T>(self) -> <a class="struct" href="structs/struct.Tuples.html" title="struct itertools::structs::Tuples">Tuples</a><Self, T> <a href="#" class="tooltip" data-notable-ty="Tuples<Self, T>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = T::Item>,
|
|||
|
T: <a class="trait" href="traits/trait.HomogeneousTuple.html" title="trait itertools::traits::HomogeneousTuple">HomogeneousTuple</a>,</div></h4></section></summary><div class="docblock"><p>Return an iterator that groups the items in tuples of a specific size
|
|||
|
(up to 12).</p>
|
|||
|
<p>See also the method <a href="trait.Itertools.html#method.next_tuple" title="method itertools::Itertools::next_tuple"><code>.next_tuple()</code></a>.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
<span class="kw">let </span><span class="kw-2">mut </span>v = Vec::new();
|
|||
|
<span class="kw">for </span>(a, b) <span class="kw">in </span>(<span class="number">1</span>..<span class="number">5</span>).tuples() {
|
|||
|
v.push((a, b));
|
|||
|
}
|
|||
|
<span class="macro">assert_eq!</span>(v, <span class="macro">vec!</span>[(<span class="number">1</span>, <span class="number">2</span>), (<span class="number">3</span>, <span class="number">4</span>)]);
|
|||
|
|
|||
|
<span class="kw">let </span><span class="kw-2">mut </span>it = (<span class="number">1</span>..<span class="number">7</span>).tuples();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>((<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>)), it.next());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>((<span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>)), it.next());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, it.next());
|
|||
|
|
|||
|
<span class="comment">// this requires a type hint
|
|||
|
</span><span class="kw">let </span>it = (<span class="number">1</span>..<span class="number">7</span>).tuples::<(<span class="kw">_</span>, <span class="kw">_</span>, <span class="kw">_</span>)>();
|
|||
|
itertools::assert_equal(it, <span class="macro">vec!</span>[(<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>), (<span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>)]);
|
|||
|
|
|||
|
<span class="comment">// you can also specify the complete type
|
|||
|
</span><span class="kw">use </span>itertools::Tuples;
|
|||
|
<span class="kw">use </span>std::ops::Range;
|
|||
|
|
|||
|
<span class="kw">let </span>it: Tuples<Range<u32>, (u32, u32, u32)> = (<span class="number">1</span>..<span class="number">7</span>).tuples();
|
|||
|
itertools::assert_equal(it, <span class="macro">vec!</span>[(<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>), (<span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>)]);</code></pre></div>
|
|||
|
<p>See also <a href="structs/struct.Tuples.html#method.into_buffer" title="method itertools::structs::Tuples::into_buffer"><code>Tuples::into_buffer</code></a>.</p>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.tee" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#788-794">source</a><h4 class="code-header">fn <a href="#method.tee" class="fn">tee</a>(self) -> (<a class="struct" href="structs/struct.Tee.html" title="struct itertools::structs::Tee">Tee</a><Self>, <a class="struct" href="structs/struct.Tee.html" title="struct itertools::structs::Tee">Tee</a><Self>)<div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,</div></h4></section></summary><div class="docblock"><p>Split into an iterator pair that both yield all elements from
|
|||
|
the original iterator.</p>
|
|||
|
<p><strong>Note:</strong> If the iterator is clonable, prefer using that instead
|
|||
|
of using this method. Cloning is likely to be more efficient.</p>
|
|||
|
<p>Iterator element type is <code>Self::Item</code>.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
<span class="kw">let </span>xs = <span class="macro">vec!</span>[<span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
|
|||
|
|
|||
|
<span class="kw">let </span>(<span class="kw-2">mut </span>t1, t2) = xs.into_iter().tee();
|
|||
|
itertools::assert_equal(t1.next(), <span class="prelude-val">Some</span>(<span class="number">0</span>));
|
|||
|
itertools::assert_equal(t2, <span class="number">0</span>..<span class="number">4</span>);
|
|||
|
itertools::assert_equal(t1, <span class="number">1</span>..<span class="number">4</span>);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.step" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#814-819">source</a><h4 class="code-header">fn <a href="#method.step" class="fn">step</a>(self, n: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -> <a class="struct" href="structs/struct.Step.html" title="struct itertools::structs::Step">Step</a><Self> <a href="#" class="tooltip" data-notable-ty="Step<Self>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span><span>Deprecated since 0.8.0: Use std .step_by() instead</span></div></span><div class="docblock"><p>Return an iterator adaptor that steps <code>n</code> elements in the base iterator
|
|||
|
for each iteration.</p>
|
|||
|
<p>The iterator steps by yielding the next element from the base iterator,
|
|||
|
then skipping forward <code>n - 1</code> elements.</p>
|
|||
|
<p>Iterator element type is <code>Self::Item</code>.</p>
|
|||
|
<p><strong>Panics</strong> if the step is 0.</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">0</span>..<span class="number">8</span>).step(<span class="number">3</span>);
|
|||
|
itertools::assert_equal(it, <span class="macro">vec!</span>[<span class="number">0</span>, <span class="number">3</span>, <span class="number">6</span>]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.map_into" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#828-834">source</a><h4 class="code-header">fn <a href="#method.map_into" class="fn">map_into</a><R>(self) -> <a class="type" href="structs/type.MapInto.html" title="type itertools::structs::MapInto">MapInto</a><Self, R><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><R>,</div></h4></section></summary><div class="docblock"><p>Convert each item of the iterator using the <a href="https://doc.rust-lang.org/1.76.0/core/convert/trait.Into.html" title="trait core::convert::Into"><code>Into</code></a> trait.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
(<span class="number">1i32</span>..<span class="number">42i32</span>).map_into::<f64>().collect_vec();</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.map_results" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#838-844">source</a><h4 class="code-header">fn <a href="#method.map_results" class="fn">map_results</a><F, T, U, E>(self, f: F) -> <a class="type" href="structs/type.MapOk.html" title="type itertools::structs::MapOk">MapOk</a><Self, F><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, E>> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(T) -> U,</div></h4></section></summary><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span><span>Deprecated since 0.10.0: Use .map_ok() instead</span></div></span><div class="docblock"><p>See <a href="trait.Itertools.html#method.map_ok" title="method itertools::Itertools::map_ok"><code>.map_ok()</code></a>.</p>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.map_ok" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#857-863">source</a><h4 class="code-header">fn <a href="#method.map_ok" class="fn">map_ok</a><F, T, U, E>(self, f: F) -> <a class="type" href="structs/type.MapOk.html" title="type itertools::structs::MapOk">MapOk</a><Self, F><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, E>> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(T) -> U,</div></h4></section></summary><div class="docblock"><p>Return an iterator adaptor that applies the provided closure
|
|||
|
to every <code>Result::Ok</code> value. <code>Result::Err</code> values are
|
|||
|
unchanged.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>input = <span class="macro">vec!</span>[<span class="prelude-val">Ok</span>(<span class="number">41</span>), <span class="prelude-val">Err</span>(<span class="bool-val">false</span>), <span class="prelude-val">Ok</span>(<span class="number">11</span>)];
|
|||
|
<span class="kw">let </span>it = input.into_iter().map_ok(|i| i + <span class="number">1</span>);
|
|||
|
itertools::assert_equal(it, <span class="macro">vec!</span>[<span class="prelude-val">Ok</span>(<span class="number">42</span>), <span class="prelude-val">Err</span>(<span class="bool-val">false</span>), <span class="prelude-val">Ok</span>(<span class="number">12</span>)]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.filter_ok" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#876-882">source</a><h4 class="code-header">fn <a href="#method.filter_ok" class="fn">filter_ok</a><F, T, E>(self, f: F) -> <a class="struct" href="structs/struct.FilterOk.html" title="struct itertools::structs::FilterOk">FilterOk</a><Self, F> <a href="#" class="tooltip" data-notable-ty="FilterOk<Self, F>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, E>> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&T</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>,</div></h4></section></summary><div class="docblock"><p>Return an iterator adaptor that filters every <code>Result::Ok</code>
|
|||
|
value with the provided closure. <code>Result::Err</code> values are
|
|||
|
unchanged.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>input = <span class="macro">vec!</span>[<span class="prelude-val">Ok</span>(<span class="number">22</span>), <span class="prelude-val">Err</span>(<span class="bool-val">false</span>), <span class="prelude-val">Ok</span>(<span class="number">11</span>)];
|
|||
|
<span class="kw">let </span>it = input.into_iter().filter_ok(|<span class="kw-2">&</span>i| i > <span class="number">20</span>);
|
|||
|
itertools::assert_equal(it, <span class="macro">vec!</span>[<span class="prelude-val">Ok</span>(<span class="number">22</span>), <span class="prelude-val">Err</span>(<span class="bool-val">false</span>)]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.filter_map_ok" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#895-901">source</a><h4 class="code-header">fn <a href="#method.filter_map_ok" class="fn">filter_map_ok</a><F, T, U, E>(self, f: F) -> <a class="struct" href="structs/struct.FilterMapOk.html" title="struct itertools::structs::FilterMapOk">FilterMapOk</a><Self, F> <a href="#" class="tooltip" data-notable-ty="FilterMapOk<Self, F>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, E>> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(T) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><U>,</div></h4></section></summary><div class="docblock"><p>Return an iterator adaptor that filters and transforms every
|
|||
|
<code>Result::Ok</code> value with the provided closure. <code>Result::Err</code>
|
|||
|
values are unchanged.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>input = <span class="macro">vec!</span>[<span class="prelude-val">Ok</span>(<span class="number">22</span>), <span class="prelude-val">Err</span>(<span class="bool-val">false</span>), <span class="prelude-val">Ok</span>(<span class="number">11</span>)];
|
|||
|
<span class="kw">let </span>it = input.into_iter().filter_map_ok(|i| <span class="kw">if </span>i > <span class="number">20 </span>{ <span class="prelude-val">Some</span>(i * <span class="number">2</span>) } <span class="kw">else </span>{ <span class="prelude-val">None </span>});
|
|||
|
itertools::assert_equal(it, <span class="macro">vec!</span>[<span class="prelude-val">Ok</span>(<span class="number">44</span>), <span class="prelude-val">Err</span>(<span class="bool-val">false</span>)]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.flatten_ok" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#920-926">source</a><h4 class="code-header">fn <a href="#method.flatten_ok" class="fn">flatten_ok</a><T, E>(self) -> <a class="struct" href="structs/struct.FlattenOk.html" title="struct itertools::structs::FlattenOk">FlattenOk</a><Self, T, E> <a href="#" class="tooltip" data-notable-ty="FlattenOk<Self, T, E>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, E>> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
T: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,</div></h4></section></summary><div class="docblock"><p>Return an iterator adaptor that flattens every <code>Result::Ok</code> value into
|
|||
|
a series of <code>Result::Ok</code> values. <code>Result::Err</code> values are unchanged.</p>
|
|||
|
<p>This is useful when you have some common error type for your crate and
|
|||
|
need to propagate it upwards, but the <code>Result::Ok</code> case needs to be flattened.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>input = <span class="macro">vec!</span>[<span class="prelude-val">Ok</span>(<span class="number">0</span>..<span class="number">2</span>), <span class="prelude-val">Err</span>(<span class="bool-val">false</span>), <span class="prelude-val">Ok</span>(<span class="number">2</span>..<span class="number">4</span>)];
|
|||
|
<span class="kw">let </span>it = input.iter().cloned().flatten_ok();
|
|||
|
itertools::assert_equal(it.clone(), <span class="macro">vec!</span>[<span class="prelude-val">Ok</span>(<span class="number">0</span>), <span class="prelude-val">Ok</span>(<span class="number">1</span>), <span class="prelude-val">Err</span>(<span class="bool-val">false</span>), <span class="prelude-val">Ok</span>(<span class="number">2</span>), <span class="prelude-val">Ok</span>(<span class="number">3</span>)]);
|
|||
|
|
|||
|
<span class="comment">// This can also be used to propagate errors when collecting.
|
|||
|
</span><span class="kw">let </span>output_result: <span class="prelude-ty">Result</span><Vec<i32>, bool> = it.collect();
|
|||
|
<span class="macro">assert_eq!</span>(output_result, <span class="prelude-val">Err</span>(<span class="bool-val">false</span>));</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.process_results" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#958-964">source</a><h4 class="code-header">fn <a href="#method.process_results" class="fn">process_results</a><F, T, E, R>(self, processor: F) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><R, E><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, E>> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(<a class="struct" href="structs/struct.ProcessResults.html" title="struct itertools::structs::ProcessResults">ProcessResults</a><'_, Self, E>) -> R,</div></h4></section></summary><div class="docblock"><p>“Lift” a function of the values of the current iterator so as to process
|
|||
|
an iterator of <code>Result</code> values instead.</p>
|
|||
|
<p><code>processor</code> is a closure that receives an adapted version of the iterator
|
|||
|
as the only argument — the adapted iterator produces elements of type <code>T</code>,
|
|||
|
as long as the original iterator produces <code>Ok</code> values.</p>
|
|||
|
<p>If the original iterable produces an error at any point, the adapted
|
|||
|
iterator ends and it will return the error iself.</p>
|
|||
|
<p>Otherwise, the return value from the closure is returned wrapped
|
|||
|
inside <code>Ok</code>.</p>
|
|||
|
<h5 id="example"><a href="#example">Example</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">type </span>Item = <span class="prelude-ty">Result</span><i32, <span class="kw-2">&</span><span class="lifetime">'static </span>str>;
|
|||
|
|
|||
|
<span class="kw">let </span>first_values: Vec<Item> = <span class="macro">vec!</span>[<span class="prelude-val">Ok</span>(<span class="number">1</span>), <span class="prelude-val">Ok</span>(<span class="number">0</span>), <span class="prelude-val">Ok</span>(<span class="number">3</span>)];
|
|||
|
<span class="kw">let </span>second_values: Vec<Item> = <span class="macro">vec!</span>[<span class="prelude-val">Ok</span>(<span class="number">2</span>), <span class="prelude-val">Ok</span>(<span class="number">1</span>), <span class="prelude-val">Err</span>(<span class="string">"overflow"</span>)];
|
|||
|
|
|||
|
<span class="comment">// “Lift” the iterator .max() method to work on the Ok-values.
|
|||
|
</span><span class="kw">let </span>first_max = first_values.into_iter().process_results(|iter| iter.max().unwrap_or(<span class="number">0</span>));
|
|||
|
<span class="kw">let </span>second_max = second_values.into_iter().process_results(|iter| iter.max().unwrap_or(<span class="number">0</span>));
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(first_max, <span class="prelude-val">Ok</span>(<span class="number">3</span>));
|
|||
|
<span class="macro">assert!</span>(second_max.is_err());</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.merge" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#980-987">source</a><h4 class="code-header">fn <a href="#method.merge" class="fn">merge</a><J>(self, other: J) -> <a class="type" href="structs/type.Merge.html" title="type itertools::structs::Merge">Merge</a><Self, J::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a>,
|
|||
|
J: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a><Item = Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>>,</div></h4></section></summary><div class="docblock"><p>Return an iterator adaptor that merges the two base iterators in
|
|||
|
ascending order. If both base iterators are sorted (ascending), the
|
|||
|
result is sorted.</p>
|
|||
|
<p>Iterator element type is <code>Self::Item</code>.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>a = (<span class="number">0</span>..<span class="number">11</span>).step_by(<span class="number">3</span>);
|
|||
|
<span class="kw">let </span>b = (<span class="number">0</span>..<span class="number">11</span>).step_by(<span class="number">5</span>);
|
|||
|
<span class="kw">let </span>it = a.merge(b);
|
|||
|
itertools::assert_equal(it, <span class="macro">vec!</span>[<span class="number">0</span>, <span class="number">0</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="number">6</span>, <span class="number">9</span>, <span class="number">10</span>]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.merge_by" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1005-1012">source</a><h4 class="code-header">fn <a href="#method.merge_by" class="fn">merge_by</a><J, F>(self, other: J, is_first: F) -> <a class="struct" href="structs/struct.MergeBy.html" title="struct itertools::structs::MergeBy">MergeBy</a><Self, J::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a>, F> <a href="#" class="tooltip" data-notable-ty="MergeBy<Self, J::IntoIter, F>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
J: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a><Item = Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, &Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>,</div></h4></section></summary><div class="docblock"><p>Return an iterator adaptor that merges the two base iterators in order.
|
|||
|
This is much like <a href="trait.Itertools.html#method.merge" title="method itertools::Itertools::merge"><code>.merge()</code></a> but allows for a custom ordering.</p>
|
|||
|
<p>This can be especially useful for sequences of tuples.</p>
|
|||
|
<p>Iterator element type is <code>Self::Item</code>.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>a = (<span class="number">0</span>..).zip(<span class="string">"bc"</span>.chars());
|
|||
|
<span class="kw">let </span>b = (<span class="number">0</span>..).zip(<span class="string">"ad"</span>.chars());
|
|||
|
<span class="kw">let </span>it = a.merge_by(b, |x, y| x.<span class="number">1 </span><= y.<span class="number">1</span>);
|
|||
|
itertools::assert_equal(it, <span class="macro">vec!</span>[(<span class="number">0</span>, <span class="string">'a'</span>), (<span class="number">0</span>, <span class="string">'b'</span>), (<span class="number">1</span>, <span class="string">'c'</span>), (<span class="number">1</span>, <span class="string">'d'</span>)]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.merge_join_by" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1072-1079">source</a><h4 class="code-header">fn <a href="#method.merge_join_by" class="fn">merge_join_by</a><J, F, T>(
|
|||
|
self,
|
|||
|
other: J,
|
|||
|
cmp_fn: F
|
|||
|
) -> <a class="type" href="structs/type.MergeJoinBy.html" title="type itertools::structs::MergeJoinBy">MergeJoinBy</a><Self, J::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a>, F><div class="where">where
|
|||
|
J: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, &J::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" title="type core::iter::traits::collect::IntoIterator::Item">Item</a>) -> T,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Create an iterator that merges items from both this and the specified
|
|||
|
iterator in ascending order.</p>
|
|||
|
<p>The function can either return an <code>Ordering</code> variant or a boolean.</p>
|
|||
|
<p>If <code>cmp_fn</code> returns <code>Ordering</code>,
|
|||
|
it chooses whether to pair elements based on the <code>Ordering</code> returned by the
|
|||
|
specified compare function. At any point, inspecting the tip of the
|
|||
|
iterators <code>I</code> and <code>J</code> as items <code>i</code> of type <code>I::Item</code> and <code>j</code> of type
|
|||
|
<code>J::Item</code> respectively, the resulting iterator will:</p>
|
|||
|
<ul>
|
|||
|
<li>Emit <code>EitherOrBoth::Left(i)</code> when <code>i < j</code>,
|
|||
|
and remove <code>i</code> from its source iterator</li>
|
|||
|
<li>Emit <code>EitherOrBoth::Right(j)</code> when <code>i > j</code>,
|
|||
|
and remove <code>j</code> from its source iterator</li>
|
|||
|
<li>Emit <code>EitherOrBoth::Both(i, j)</code> when <code>i == j</code>,
|
|||
|
and remove both <code>i</code> and <code>j</code> from their respective source iterators</li>
|
|||
|
</ul>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
<span class="kw">use </span>itertools::EitherOrBoth::{Left, Right, Both};
|
|||
|
|
|||
|
<span class="kw">let </span>a = <span class="macro">vec!</span>[<span class="number">0</span>, <span class="number">2</span>, <span class="number">4</span>, <span class="number">6</span>, <span class="number">1</span>].into_iter();
|
|||
|
<span class="kw">let </span>b = (<span class="number">0</span>..<span class="number">10</span>).step_by(<span class="number">3</span>);
|
|||
|
|
|||
|
itertools::assert_equal(
|
|||
|
a.merge_join_by(b, |i, j| i.cmp(j)),
|
|||
|
<span class="macro">vec!</span>[Both(<span class="number">0</span>, <span class="number">0</span>), Left(<span class="number">2</span>), Right(<span class="number">3</span>), Left(<span class="number">4</span>), Both(<span class="number">6</span>, <span class="number">6</span>), Left(<span class="number">1</span>), Right(<span class="number">9</span>)]
|
|||
|
);</code></pre></div>
|
|||
|
<p>If <code>cmp_fn</code> returns <code>bool</code>,
|
|||
|
it chooses whether to pair elements based on the boolean returned by the
|
|||
|
specified function. At any point, inspecting the tip of the
|
|||
|
iterators <code>I</code> and <code>J</code> as items <code>i</code> of type <code>I::Item</code> and <code>j</code> of type
|
|||
|
<code>J::Item</code> respectively, the resulting iterator will:</p>
|
|||
|
<ul>
|
|||
|
<li>Emit <code>Either::Left(i)</code> when <code>true</code>,
|
|||
|
and remove <code>i</code> from its source iterator</li>
|
|||
|
<li>Emit <code>Either::Right(j)</code> when <code>false</code>,
|
|||
|
and remove <code>j</code> from its source iterator</li>
|
|||
|
</ul>
|
|||
|
<p>It is similar to the <code>Ordering</code> case if the first argument is considered
|
|||
|
“less” than the second argument.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
<span class="kw">use </span>itertools::Either::{Left, Right};
|
|||
|
|
|||
|
<span class="kw">let </span>a = <span class="macro">vec!</span>[<span class="number">0</span>, <span class="number">2</span>, <span class="number">4</span>, <span class="number">6</span>, <span class="number">1</span>].into_iter();
|
|||
|
<span class="kw">let </span>b = (<span class="number">0</span>..<span class="number">10</span>).step_by(<span class="number">3</span>);
|
|||
|
|
|||
|
itertools::assert_equal(
|
|||
|
a.merge_join_by(b, |i, j| i <= j),
|
|||
|
<span class="macro">vec!</span>[Left(<span class="number">0</span>), Right(<span class="number">0</span>), Left(<span class="number">2</span>), Right(<span class="number">3</span>), Left(<span class="number">4</span>), Left(<span class="number">6</span>), Left(<span class="number">1</span>), Right(<span class="number">6</span>), Right(<span class="number">9</span>)]
|
|||
|
);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.kmerge" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1098-1105">source</a><h4 class="code-header">fn <a href="#method.kmerge" class="fn">kmerge</a>(self) -> <a class="type" href="structs/type.KMerge.html" title="type itertools::structs::KMerge">KMerge</a><<Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a> as <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,
|
|||
|
<Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a> as <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" title="type core::iter::traits::collect::IntoIterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a>,</div></h4></section></summary><div class="docblock"><p>Return an iterator adaptor that flattens an iterator of iterators by
|
|||
|
merging them in ascending order.</p>
|
|||
|
<p>If all base iterators are sorted (ascending), the result is sorted.</p>
|
|||
|
<p>Iterator element type is <code>Self::Item</code>.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>a = (<span class="number">0</span>..<span class="number">6</span>).step_by(<span class="number">3</span>);
|
|||
|
<span class="kw">let </span>b = (<span class="number">1</span>..<span class="number">6</span>).step_by(<span class="number">3</span>);
|
|||
|
<span class="kw">let </span>c = (<span class="number">2</span>..<span class="number">6</span>).step_by(<span class="number">3</span>);
|
|||
|
<span class="kw">let </span>it = <span class="macro">vec!</span>[a, b, c].into_iter().kmerge();
|
|||
|
itertools::assert_equal(it, <span class="macro">vec!</span>[<span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.kmerge_by" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1128-1135">source</a><h4 class="code-header">fn <a href="#method.kmerge_by" class="fn">kmerge_by</a><F>(
|
|||
|
self,
|
|||
|
first: F
|
|||
|
) -> <a class="struct" href="structs/struct.KMergeBy.html" title="struct itertools::structs::KMergeBy">KMergeBy</a><<Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a> as <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a>, F> <a href="#" class="tooltip" data-notable-ty="KMergeBy<<Self::Item as IntoIterator>::IntoIter, F>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&<Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a> as <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" title="type core::iter::traits::collect::IntoIterator::Item">Item</a>, &<Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a> as <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" title="type core::iter::traits::collect::IntoIterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>,</div></h4></section></summary><div class="docblock"><p>Return an iterator adaptor that flattens an iterator of iterators by
|
|||
|
merging them according to the given closure.</p>
|
|||
|
<p>The closure <code>first</code> is called with two elements <em>a</em>, <em>b</em> and should
|
|||
|
return <code>true</code> if <em>a</em> is ordered before <em>b</em>.</p>
|
|||
|
<p>If all base iterators are sorted according to <code>first</code>, the result is
|
|||
|
sorted.</p>
|
|||
|
<p>Iterator element type is <code>Self::Item</code>.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>a = <span class="macro">vec!</span>[-<span class="number">1f64</span>, <span class="number">2.</span>, <span class="number">3.</span>, -<span class="number">5.</span>, <span class="number">6.</span>, -<span class="number">7.</span>];
|
|||
|
<span class="kw">let </span>b = <span class="macro">vec!</span>[<span class="number">0.</span>, <span class="number">2.</span>, -<span class="number">4.</span>];
|
|||
|
<span class="kw">let </span><span class="kw-2">mut </span>it = <span class="macro">vec!</span>[a, b].into_iter().kmerge_by(|a, b| a.abs() < b.abs());
|
|||
|
<span class="macro">assert_eq!</span>(it.next(), <span class="prelude-val">Some</span>(<span class="number">0.</span>));
|
|||
|
<span class="macro">assert_eq!</span>(it.last(), <span class="prelude-val">Some</span>(-<span class="number">7.</span>));</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.cartesian_product" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1148-1156">source</a><h4 class="code-header">fn <a href="#method.cartesian_product" class="fn">cartesian_product</a><J>(self, other: J) -> <a class="struct" href="structs/struct.Product.html" title="struct itertools::structs::Product">Product</a><Self, J::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a>> <a href="#" class="tooltip" data-notable-ty="Product<Self, J::IntoIter>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,
|
|||
|
J: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,
|
|||
|
J::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,</div></h4></section></summary><div class="docblock"><p>Return an iterator adaptor that iterates over the cartesian product of
|
|||
|
the element sets of two iterators <code>self</code> and <code>J</code>.</p>
|
|||
|
<p>Iterator element type is <code>(Self::Item, J::Item)</code>.</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">0</span>..<span class="number">2</span>).cartesian_product(<span class="string">"αβ"</span>.chars());
|
|||
|
itertools::assert_equal(it, <span class="macro">vec!</span>[(<span class="number">0</span>, <span class="string">'α'</span>), (<span class="number">0</span>, <span class="string">'β'</span>), (<span class="number">1</span>, <span class="string">'α'</span>), (<span class="number">1</span>, <span class="string">'β'</span>)]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.multi_cartesian_product" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1184-1192">source</a><h4 class="code-header">fn <a href="#method.multi_cartesian_product" class="fn">multi_cartesian_product</a>(
|
|||
|
self
|
|||
|
) -> <a class="struct" href="structs/struct.MultiProduct.html" title="struct itertools::structs::MultiProduct">MultiProduct</a><<Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a> as <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a>> <a href="#" class="tooltip" data-notable-ty="MultiProduct<<Self::Item as IntoIterator>::IntoIter>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,
|
|||
|
<Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a> as <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,
|
|||
|
<Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a> as <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" title="type core::iter::traits::collect::IntoIterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,</div></h4></section></summary><div class="docblock"><p>Return an iterator adaptor that iterates over the cartesian product of
|
|||
|
all subiterators returned by meta-iterator <code>self</code>.</p>
|
|||
|
<p>All provided iterators must yield the same <code>Item</code> type. To generate
|
|||
|
the product of iterators yielding multiple types, use the
|
|||
|
<a href="macro.iproduct.html" title="macro itertools::iproduct"><code>iproduct</code></a> macro instead.</p>
|
|||
|
<p>The iterator element type is <code>Vec<T></code>, where <code>T</code> is the iterator element
|
|||
|
of the subiterators.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
<span class="kw">let </span><span class="kw-2">mut </span>multi_prod = (<span class="number">0</span>..<span class="number">3</span>).map(|i| (i * <span class="number">2</span>)..(i * <span class="number">2 </span>+ <span class="number">2</span>))
|
|||
|
.multi_cartesian_product();
|
|||
|
<span class="macro">assert_eq!</span>(multi_prod.next(), <span class="prelude-val">Some</span>(<span class="macro">vec!</span>[<span class="number">0</span>, <span class="number">2</span>, <span class="number">4</span>]));
|
|||
|
<span class="macro">assert_eq!</span>(multi_prod.next(), <span class="prelude-val">Some</span>(<span class="macro">vec!</span>[<span class="number">0</span>, <span class="number">2</span>, <span class="number">5</span>]));
|
|||
|
<span class="macro">assert_eq!</span>(multi_prod.next(), <span class="prelude-val">Some</span>(<span class="macro">vec!</span>[<span class="number">0</span>, <span class="number">3</span>, <span class="number">4</span>]));
|
|||
|
<span class="macro">assert_eq!</span>(multi_prod.next(), <span class="prelude-val">Some</span>(<span class="macro">vec!</span>[<span class="number">0</span>, <span class="number">3</span>, <span class="number">5</span>]));
|
|||
|
<span class="macro">assert_eq!</span>(multi_prod.next(), <span class="prelude-val">Some</span>(<span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">4</span>]));
|
|||
|
<span class="macro">assert_eq!</span>(multi_prod.next(), <span class="prelude-val">Some</span>(<span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">5</span>]));
|
|||
|
<span class="macro">assert_eq!</span>(multi_prod.next(), <span class="prelude-val">Some</span>(<span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">3</span>, <span class="number">4</span>]));
|
|||
|
<span class="macro">assert_eq!</span>(multi_prod.next(), <span class="prelude-val">Some</span>(<span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">3</span>, <span class="number">5</span>]));
|
|||
|
<span class="macro">assert_eq!</span>(multi_prod.next(), <span class="prelude-val">None</span>);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.coalesce" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1222-1228">source</a><h4 class="code-header">fn <a href="#method.coalesce" class="fn">coalesce</a><F>(self, f: F) -> <a class="type" href="structs/type.Coalesce.html" title="type itertools::structs::Coalesce">Coalesce</a><Self, F><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, (Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>)>,</div></h4></section></summary><div class="docblock"><p>Return an iterator adaptor that uses the passed-in closure to
|
|||
|
optionally merge together consecutive elements.</p>
|
|||
|
<p>The closure <code>f</code> is passed two elements, <code>previous</code> and <code>current</code> and may
|
|||
|
return either (1) <code>Ok(combined)</code> to merge the two values or
|
|||
|
(2) <code>Err((previous', current'))</code> to indicate they can’t be merged.
|
|||
|
In (2), the value <code>previous'</code> is emitted by the iterator.
|
|||
|
Either (1) <code>combined</code> or (2) <code>current'</code> becomes the previous value
|
|||
|
when coalesce continues with the next pair of elements to merge. The
|
|||
|
value that remains at the end is also emitted by the iterator.</p>
|
|||
|
<p>Iterator element type is <code>Self::Item</code>.</p>
|
|||
|
<p>This iterator is <em>fused</em>.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="comment">// sum same-sign runs together
|
|||
|
</span><span class="kw">let </span>data = <span class="macro">vec!</span>[-<span class="number">1.</span>, -<span class="number">2.</span>, -<span class="number">3.</span>, <span class="number">3.</span>, <span class="number">1.</span>, <span class="number">0.</span>, -<span class="number">1.</span>];
|
|||
|
itertools::assert_equal(data.into_iter().coalesce(|x, y|
|
|||
|
<span class="kw">if </span>(x >= <span class="number">0.</span>) == (y >= <span class="number">0.</span>) {
|
|||
|
<span class="prelude-val">Ok</span>(x + y)
|
|||
|
} <span class="kw">else </span>{
|
|||
|
<span class="prelude-val">Err</span>((x, y))
|
|||
|
}),
|
|||
|
<span class="macro">vec!</span>[-<span class="number">6.</span>, <span class="number">4.</span>, -<span class="number">1.</span>]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.dedup" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1244-1250">source</a><h4 class="code-header">fn <a href="#method.dedup" class="fn">dedup</a>(self) -> <a class="type" href="structs/type.Dedup.html" title="type itertools::structs::Dedup">Dedup</a><Self><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a>,</div></h4></section></summary><div class="docblock"><p>Remove duplicates from sections of consecutive identical elements.
|
|||
|
If the iterator is sorted, all elements will be unique.</p>
|
|||
|
<p>Iterator element type is <code>Self::Item</code>.</p>
|
|||
|
<p>This iterator is <em>fused</em>.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>data = <span class="macro">vec!</span>[<span class="number">1.</span>, <span class="number">1.</span>, <span class="number">2.</span>, <span class="number">3.</span>, <span class="number">3.</span>, <span class="number">2.</span>, <span class="number">2.</span>];
|
|||
|
itertools::assert_equal(data.into_iter().dedup(),
|
|||
|
<span class="macro">vec!</span>[<span class="number">1.</span>, <span class="number">2.</span>, <span class="number">3.</span>, <span class="number">2.</span>]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.dedup_by" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1267-1273">source</a><h4 class="code-header">fn <a href="#method.dedup_by" class="fn">dedup_by</a><Cmp>(self, cmp: Cmp) -> <a class="type" href="structs/type.DedupBy.html" title="type itertools::structs::DedupBy">DedupBy</a><Self, Cmp><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Cmp: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, &Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>,</div></h4></section></summary><div class="docblock"><p>Remove duplicates from sections of consecutive identical elements,
|
|||
|
determining equality using a comparison function.
|
|||
|
If the iterator is sorted, all elements will be unique.</p>
|
|||
|
<p>Iterator element type is <code>Self::Item</code>.</p>
|
|||
|
<p>This iterator is <em>fused</em>.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>data = <span class="macro">vec!</span>[(<span class="number">0</span>, <span class="number">1.</span>), (<span class="number">1</span>, <span class="number">1.</span>), (<span class="number">0</span>, <span class="number">2.</span>), (<span class="number">0</span>, <span class="number">3.</span>), (<span class="number">1</span>, <span class="number">3.</span>), (<span class="number">1</span>, <span class="number">2.</span>), (<span class="number">2</span>, <span class="number">2.</span>)];
|
|||
|
itertools::assert_equal(data.into_iter().dedup_by(|x, y| x.<span class="number">1 </span>== y.<span class="number">1</span>),
|
|||
|
<span class="macro">vec!</span>[(<span class="number">0</span>, <span class="number">1.</span>), (<span class="number">0</span>, <span class="number">2.</span>), (<span class="number">0</span>, <span class="number">3.</span>), (<span class="number">1</span>, <span class="number">2.</span>)]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.dedup_with_count" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1290-1295">source</a><h4 class="code-header">fn <a href="#method.dedup_with_count" class="fn">dedup_with_count</a>(self) -> <a class="type" href="structs/type.DedupWithCount.html" title="type itertools::structs::DedupWithCount">DedupWithCount</a><Self><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Remove duplicates from sections of consecutive identical elements, while keeping a count of
|
|||
|
how many repeated elements were present.
|
|||
|
If the iterator is sorted, all elements will be unique.</p>
|
|||
|
<p>Iterator element type is <code>(usize, Self::Item)</code>.</p>
|
|||
|
<p>This iterator is <em>fused</em>.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>data = <span class="macro">vec!</span>[<span class="string">'a'</span>, <span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>, <span class="string">'c'</span>, <span class="string">'b'</span>, <span class="string">'b'</span>];
|
|||
|
itertools::assert_equal(data.into_iter().dedup_with_count(),
|
|||
|
<span class="macro">vec!</span>[(<span class="number">2</span>, <span class="string">'a'</span>), (<span class="number">1</span>, <span class="string">'b'</span>), (<span class="number">2</span>, <span class="string">'c'</span>), (<span class="number">2</span>, <span class="string">'b'</span>)]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.dedup_by_with_count" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1313-1319">source</a><h4 class="code-header">fn <a href="#method.dedup_by_with_count" class="fn">dedup_by_with_count</a><Cmp>(self, cmp: Cmp) -> <a class="type" href="structs/type.DedupByWithCount.html" title="type itertools::structs::DedupByWithCount">DedupByWithCount</a><Self, Cmp><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Cmp: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, &Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>,</div></h4></section></summary><div class="docblock"><p>Remove duplicates from sections of consecutive identical elements, while keeping a count of
|
|||
|
how many repeated elements were present.
|
|||
|
This will determine equality using a comparison function.
|
|||
|
If the iterator is sorted, all elements will be unique.</p>
|
|||
|
<p>Iterator element type is <code>(usize, Self::Item)</code>.</p>
|
|||
|
<p>This iterator is <em>fused</em>.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>data = <span class="macro">vec!</span>[(<span class="number">0</span>, <span class="string">'a'</span>), (<span class="number">1</span>, <span class="string">'a'</span>), (<span class="number">0</span>, <span class="string">'b'</span>), (<span class="number">0</span>, <span class="string">'c'</span>), (<span class="number">1</span>, <span class="string">'c'</span>), (<span class="number">1</span>, <span class="string">'b'</span>), (<span class="number">2</span>, <span class="string">'b'</span>)];
|
|||
|
itertools::assert_equal(data.into_iter().dedup_by_with_count(|x, y| x.<span class="number">1 </span>== y.<span class="number">1</span>),
|
|||
|
<span class="macro">vec!</span>[(<span class="number">2</span>, (<span class="number">0</span>, <span class="string">'a'</span>)), (<span class="number">1</span>, (<span class="number">0</span>, <span class="string">'b'</span>)), (<span class="number">2</span>, (<span class="number">0</span>, <span class="string">'c'</span>)), (<span class="number">2</span>, (<span class="number">1</span>, <span class="string">'b'</span>))]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.duplicates" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1336-1342">source</a><h4 class="code-header">fn <a href="#method.duplicates" class="fn">duplicates</a>(self) -> <a class="type" href="structs/type.Duplicates.html" title="type itertools::structs::Duplicates">Duplicates</a><Self><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a>,</div></h4></section></summary><div class="docblock"><p>Return an iterator adaptor that produces elements that appear more than once during the
|
|||
|
iteration. Duplicates are detected using hash and equality.</p>
|
|||
|
<p>The iterator is stable, returning the duplicate items in the order in which they occur in
|
|||
|
the adapted iterator. Each duplicate item is returned exactly once. If an item appears more
|
|||
|
than twice, the second item is the item retained and the rest are discarded.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>data = <span class="macro">vec!</span>[<span class="number">10</span>, <span class="number">20</span>, <span class="number">30</span>, <span class="number">20</span>, <span class="number">40</span>, <span class="number">10</span>, <span class="number">50</span>];
|
|||
|
itertools::assert_equal(data.into_iter().duplicates(),
|
|||
|
<span class="macro">vec!</span>[<span class="number">20</span>, <span class="number">10</span>]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.duplicates_by" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1362-1369">source</a><h4 class="code-header">fn <a href="#method.duplicates_by" class="fn">duplicates_by</a><V, F>(self, f: F) -> <a class="type" href="structs/type.DuplicatesBy.html" title="type itertools::structs::DuplicatesBy">DuplicatesBy</a><Self, V, F><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
V: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> V,</div></h4></section></summary><div class="docblock"><p>Return an iterator adaptor that produces elements that appear more than once during the
|
|||
|
iteration. Duplicates are detected using hash and equality.</p>
|
|||
|
<p>Duplicates are detected by comparing the key they map to with the keying function <code>f</code> by
|
|||
|
hash and equality. The keys are stored in a hash map in the iterator.</p>
|
|||
|
<p>The iterator is stable, returning the duplicate items in the order in which they occur in
|
|||
|
the adapted iterator. Each duplicate item is returned exactly once. If an item appears more
|
|||
|
than twice, the second item is the item retained and the rest are discarded.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>data = <span class="macro">vec!</span>[<span class="string">"a"</span>, <span class="string">"bb"</span>, <span class="string">"aa"</span>, <span class="string">"c"</span>, <span class="string">"ccc"</span>];
|
|||
|
itertools::assert_equal(data.into_iter().duplicates_by(|s| s.len()),
|
|||
|
<span class="macro">vec!</span>[<span class="string">"aa"</span>, <span class="string">"c"</span>]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.unique" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1390-1396">source</a><h4 class="code-header">fn <a href="#method.unique" class="fn">unique</a>(self) -> <a class="struct" href="structs/struct.Unique.html" title="struct itertools::structs::Unique">Unique</a><Self> <a href="#" class="tooltip" data-notable-ty="Unique<Self>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a>,</div></h4></section></summary><div class="docblock"><p>Return an iterator adaptor that filters out elements that have
|
|||
|
already been produced once during the iteration. Duplicates
|
|||
|
are detected using hash and equality.</p>
|
|||
|
<p>Clones of visited elements are stored in a hash set in the
|
|||
|
iterator.</p>
|
|||
|
<p>The iterator is stable, returning the non-duplicate items in the order
|
|||
|
in which they occur in the adapted iterator. In a set of duplicate
|
|||
|
items, the first item encountered is the item retained.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>data = <span class="macro">vec!</span>[<span class="number">10</span>, <span class="number">20</span>, <span class="number">30</span>, <span class="number">20</span>, <span class="number">40</span>, <span class="number">10</span>, <span class="number">50</span>];
|
|||
|
itertools::assert_equal(data.into_iter().unique(),
|
|||
|
<span class="macro">vec!</span>[<span class="number">10</span>, <span class="number">20</span>, <span class="number">30</span>, <span class="number">40</span>, <span class="number">50</span>]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.unique_by" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1417-1424">source</a><h4 class="code-header">fn <a href="#method.unique_by" class="fn">unique_by</a><V, F>(self, f: F) -> <a class="struct" href="structs/struct.UniqueBy.html" title="struct itertools::structs::UniqueBy">UniqueBy</a><Self, V, F> <a href="#" class="tooltip" data-notable-ty="UniqueBy<Self, V, F>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
V: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> V,</div></h4></section></summary><div class="docblock"><p>Return an iterator adaptor that filters out elements that have
|
|||
|
already been produced once during the iteration.</p>
|
|||
|
<p>Duplicates are detected by comparing the key they map to
|
|||
|
with the keying function <code>f</code> by hash and equality.
|
|||
|
The keys are stored in a hash set in the iterator.</p>
|
|||
|
<p>The iterator is stable, returning the non-duplicate items in the order
|
|||
|
in which they occur in the adapted iterator. In a set of duplicate
|
|||
|
items, the first item encountered is the item retained.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>data = <span class="macro">vec!</span>[<span class="string">"a"</span>, <span class="string">"bb"</span>, <span class="string">"aa"</span>, <span class="string">"c"</span>, <span class="string">"ccc"</span>];
|
|||
|
itertools::assert_equal(data.into_iter().unique_by(|s| s.len()),
|
|||
|
<span class="macro">vec!</span>[<span class="string">"a"</span>, <span class="string">"bb"</span>, <span class="string">"ccc"</span>]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.peeking_take_while" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1438-1444">source</a><h4 class="code-header">fn <a href="#method.peeking_take_while" class="fn">peeking_take_while</a><F>(&mut self, accept: F) -> <a class="struct" href="structs/struct.PeekingTakeWhile.html" title="struct itertools::structs::PeekingTakeWhile">PeekingTakeWhile</a><'_, Self, F> <a href="#" class="tooltip" data-notable-ty="PeekingTakeWhile<'_, Self, F>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="trait.PeekingNext.html" title="trait itertools::PeekingNext">PeekingNext</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>,</div></h4></section></summary><div class="docblock"><p>Return an iterator adaptor that borrows from this iterator and
|
|||
|
takes items while the closure <code>accept</code> returns <code>true</code>.</p>
|
|||
|
<p>This adaptor can only be used on iterators that implement <code>PeekingNext</code>
|
|||
|
like <code>.peekable()</code>, <code>put_back</code> and a few other collection iterators.</p>
|
|||
|
<p>The last and rejected element (first <code>false</code>) is still available when
|
|||
|
<code>peeking_take_while</code> is done.</p>
|
|||
|
<p>See also <a href="trait.Itertools.html#method.take_while_ref" title="method itertools::Itertools::take_while_ref"><code>.take_while_ref()</code></a>
|
|||
|
which is a similar adaptor.</p>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.take_while_ref" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1464-1470">source</a><h4 class="code-header">fn <a href="#method.take_while_ref" class="fn">take_while_ref</a><F>(&mut self, accept: F) -> <a class="struct" href="structs/struct.TakeWhileRef.html" title="struct itertools::structs::TakeWhileRef">TakeWhileRef</a><'_, Self, F> <a href="#" class="tooltip" data-notable-ty="TakeWhileRef<'_, Self, F>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>,</div></h4></section></summary><div class="docblock"><p>Return an iterator adaptor that borrows from a <code>Clone</code>-able iterator
|
|||
|
to only pick off elements while the predicate <code>accept</code> returns <code>true</code>.</p>
|
|||
|
<p>It uses the <code>Clone</code> trait to restore the original iterator so that the
|
|||
|
last and rejected element (first <code>false</code>) is still available when
|
|||
|
<code>take_while_ref</code> is done.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span><span class="kw-2">mut </span>hexadecimals = <span class="string">"0123456789abcdef"</span>.chars();
|
|||
|
|
|||
|
<span class="kw">let </span>decimals = hexadecimals.take_while_ref(|c| c.is_numeric())
|
|||
|
.collect::<String>();
|
|||
|
<span class="macro">assert_eq!</span>(decimals, <span class="string">"0123456789"</span>);
|
|||
|
<span class="macro">assert_eq!</span>(hexadecimals.next(), <span class="prelude-val">Some</span>(<span class="string">'a'</span>));
|
|||
|
</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.take_while_inclusive" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1532-1538">source</a><h4 class="code-header">fn <a href="#method.take_while_inclusive" class="fn">take_while_inclusive</a><F>(self, accept: F) -> <a class="struct" href="structs/struct.TakeWhileInclusive.html" title="struct itertools::structs::TakeWhileInclusive">TakeWhileInclusive</a><Self, F> <a href="#" class="tooltip" data-notable-ty="TakeWhileInclusive<Self, F>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>,</div></h4></section></summary><div class="docblock"><p>Returns an iterator adaptor that consumes elements while the given
|
|||
|
predicate is <code>true</code>, <em>including</em> the element for which the predicate
|
|||
|
first returned <code>false</code>.</p>
|
|||
|
<p>The <a href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#method.take_while" title="method core::iter::traits::iterator::Iterator::take_while"><code>.take_while()</code></a> adaptor is useful
|
|||
|
when you want items satisfying a predicate, but to know when to stop
|
|||
|
taking elements, we have to consume that first element that doesn’t
|
|||
|
satisfy the predicate. This adaptor includes that element where
|
|||
|
<a href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#method.take_while" title="method core::iter::traits::iterator::Iterator::take_while"><code>.take_while()</code></a> would drop it.</p>
|
|||
|
<p>The <a href="trait.Itertools.html#method.take_while_ref" title="method itertools::Itertools::take_while_ref"><code>.take_while_ref()</code></a> adaptor
|
|||
|
serves a similar purpose, but this adaptor doesn’t require <a href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone"><code>Clone</code></a>ing
|
|||
|
the underlying elements.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>items = <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>];
|
|||
|
<span class="kw">let </span>filtered: Vec<<span class="kw">_</span>> = items
|
|||
|
.into_iter()
|
|||
|
.take_while_inclusive(|<span class="kw-2">&</span>n| n % <span class="number">3 </span>!= <span class="number">0</span>)
|
|||
|
.collect();
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(filtered, <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]);</code></pre></div>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>items = <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>];
|
|||
|
|
|||
|
<span class="kw">let </span>take_while_inclusive_result: Vec<<span class="kw">_</span>> = items
|
|||
|
.iter()
|
|||
|
.copied()
|
|||
|
.take_while_inclusive(|<span class="kw-2">&</span>n| n % <span class="number">3 </span>!= <span class="number">0</span>)
|
|||
|
.collect();
|
|||
|
<span class="kw">let </span>take_while_result: Vec<<span class="kw">_</span>> = items
|
|||
|
.into_iter()
|
|||
|
.take_while(|<span class="kw-2">&</span>n| n % <span class="number">3 </span>!= <span class="number">0</span>)
|
|||
|
.collect();
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(take_while_inclusive_result, <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]);
|
|||
|
<span class="macro">assert_eq!</span>(take_while_result, <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>]);
|
|||
|
<span class="comment">// both iterators have the same items remaining at this point---the 3
|
|||
|
// is lost from the `take_while` vec</span></code></pre></div>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[derive(Debug, PartialEq)]
|
|||
|
</span><span class="kw">struct </span>NoCloneImpl(i32);
|
|||
|
|
|||
|
<span class="kw">let </span>non_clonable_items: Vec<<span class="kw">_</span>> = <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>]
|
|||
|
.into_iter()
|
|||
|
.map(NoCloneImpl)
|
|||
|
.collect();
|
|||
|
<span class="kw">let </span>filtered: Vec<<span class="kw">_</span>> = non_clonable_items
|
|||
|
.into_iter()
|
|||
|
.take_while_inclusive(|n| n.<span class="number">0 </span>% <span class="number">3 </span>!= <span class="number">0</span>)
|
|||
|
.collect();
|
|||
|
<span class="kw">let </span>expected: Vec<<span class="kw">_</span>> = <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>].into_iter().map(NoCloneImpl).collect();
|
|||
|
<span class="macro">assert_eq!</span>(filtered, expected);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.while_some" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1554-1559">source</a><h4 class="code-header">fn <a href="#method.while_some" class="fn">while_some</a><A>(self) -> <a class="struct" href="structs/struct.WhileSome.html" title="struct itertools::structs::WhileSome">WhileSome</a><Self> <a href="#" class="tooltip" data-notable-ty="WhileSome<Self>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><A>>,</div></h4></section></summary><div class="docblock"><p>Return an iterator adaptor that filters <code>Option<A></code> iterator elements
|
|||
|
and produces <code>A</code>. Stops on the first <code>None</code> encountered.</p>
|
|||
|
<p>Iterator element type is <code>A</code>, the unwrapped element.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="comment">// List all hexadecimal digits
|
|||
|
</span>itertools::assert_equal(
|
|||
|
(<span class="number">0</span>..).map(|i| std::char::from_digit(i, <span class="number">16</span>)).while_some(),
|
|||
|
<span class="string">"0123456789abcdef"</span>.chars());
|
|||
|
</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.tuple_combinations" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1599-1606">source</a><h4 class="code-header">fn <a href="#method.tuple_combinations" class="fn">tuple_combinations</a><T>(self) -> <a class="struct" href="structs/struct.TupleCombinations.html" title="struct itertools::structs::TupleCombinations">TupleCombinations</a><Self, T> <a href="#" class="tooltip" data-notable-ty="TupleCombinations<Self, T>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,
|
|||
|
T: HasCombination<Self>,</div></h4></section></summary><div class="docblock"><p>Return an iterator adaptor that iterates over the combinations of the
|
|||
|
elements from an iterator.</p>
|
|||
|
<p>Iterator element can be any homogeneous tuple of type <code>Self::Item</code> with
|
|||
|
size up to 12.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span><span class="kw-2">mut </span>v = Vec::new();
|
|||
|
<span class="kw">for </span>(a, b) <span class="kw">in </span>(<span class="number">1</span>..<span class="number">5</span>).tuple_combinations() {
|
|||
|
v.push((a, b));
|
|||
|
}
|
|||
|
<span class="macro">assert_eq!</span>(v, <span class="macro">vec!</span>[(<span class="number">1</span>, <span class="number">2</span>), (<span class="number">1</span>, <span class="number">3</span>), (<span class="number">1</span>, <span class="number">4</span>), (<span class="number">2</span>, <span class="number">3</span>), (<span class="number">2</span>, <span class="number">4</span>), (<span class="number">3</span>, <span class="number">4</span>)]);
|
|||
|
|
|||
|
<span class="kw">let </span><span class="kw-2">mut </span>it = (<span class="number">1</span>..<span class="number">5</span>).tuple_combinations();
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>((<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>)), it.next());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>((<span class="number">1</span>, <span class="number">2</span>, <span class="number">4</span>)), it.next());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>((<span class="number">1</span>, <span class="number">3</span>, <span class="number">4</span>)), it.next());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>((<span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>)), it.next());
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, it.next());
|
|||
|
|
|||
|
<span class="comment">// this requires a type hint
|
|||
|
</span><span class="kw">let </span>it = (<span class="number">1</span>..<span class="number">5</span>).tuple_combinations::<(<span class="kw">_</span>, <span class="kw">_</span>, <span class="kw">_</span>)>();
|
|||
|
itertools::assert_equal(it, <span class="macro">vec!</span>[(<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>), (<span class="number">1</span>, <span class="number">2</span>, <span class="number">4</span>), (<span class="number">1</span>, <span class="number">3</span>, <span class="number">4</span>), (<span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>)]);
|
|||
|
|
|||
|
<span class="comment">// you can also specify the complete type
|
|||
|
</span><span class="kw">use </span>itertools::TupleCombinations;
|
|||
|
<span class="kw">use </span>std::ops::Range;
|
|||
|
|
|||
|
<span class="kw">let </span>it: TupleCombinations<Range<u32>, (u32, u32, u32)> = (<span class="number">1</span>..<span class="number">5</span>).tuple_combinations();
|
|||
|
itertools::assert_equal(it, <span class="macro">vec!</span>[(<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>), (<span class="number">1</span>, <span class="number">2</span>, <span class="number">4</span>), (<span class="number">1</span>, <span class="number">3</span>, <span class="number">4</span>), (<span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>)]);</code></pre></div>
|
|||
|
<h5 id="guarantees"><a href="#guarantees">Guarantees</a></h5>
|
|||
|
<p>If the adapted iterator is deterministic,
|
|||
|
this iterator adapter yields items in a reliable order.</p>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.combinations" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1643-1649">source</a><h4 class="code-header">fn <a href="#method.combinations" class="fn">combinations</a>(self, k: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -> <a class="struct" href="structs/struct.Combinations.html" title="struct itertools::structs::Combinations">Combinations</a><Self> <a href="#" class="tooltip" data-notable-ty="Combinations<Self>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,</div></h4></section></summary><div class="docblock"><p>Return an iterator adaptor that iterates over the <code>k</code>-length combinations of
|
|||
|
the elements from an iterator.</p>
|
|||
|
<p>Iterator element type is <code>Vec<Self::Item></code>. The iterator produces a new Vec per iteration,
|
|||
|
and clones the iterator elements.</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">5</span>).combinations(<span class="number">3</span>);
|
|||
|
itertools::assert_equal(it, <span class="macro">vec!</span>[
|
|||
|
<span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>],
|
|||
|
<span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">4</span>],
|
|||
|
<span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">3</span>, <span class="number">4</span>],
|
|||
|
<span class="macro">vec!</span>[<span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>],
|
|||
|
]);</code></pre></div>
|
|||
|
<p>Note: Combinations does not take into account the equality of the iterated values.</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="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">2</span>].into_iter().combinations(<span class="number">2</span>);
|
|||
|
itertools::assert_equal(it, <span class="macro">vec!</span>[
|
|||
|
<span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>], <span class="comment">// Note: these are the same
|
|||
|
</span><span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>], <span class="comment">// Note: these are the same
|
|||
|
</span><span class="macro">vec!</span>[<span class="number">2</span>, <span class="number">2</span>],
|
|||
|
]);</code></pre></div>
|
|||
|
<h5 id="guarantees-1"><a href="#guarantees-1">Guarantees</a></h5>
|
|||
|
<p>If the adapted iterator is deterministic,
|
|||
|
this iterator adapter yields items in a reliable order.</p>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.combinations_with_replacement" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1671-1677">source</a><h4 class="code-header">fn <a href="#method.combinations_with_replacement" class="fn">combinations_with_replacement</a>(
|
|||
|
self,
|
|||
|
k: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>
|
|||
|
) -> <a class="struct" href="structs/struct.CombinationsWithReplacement.html" title="struct itertools::structs::CombinationsWithReplacement">CombinationsWithReplacement</a><Self> <a href="#" class="tooltip" data-notable-ty="CombinationsWithReplacement<Self>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,</div></h4></section></summary><div class="docblock"><p>Return an iterator that iterates over the <code>k</code>-length combinations of
|
|||
|
the elements from an iterator, with replacement.</p>
|
|||
|
<p>Iterator element type is <code>Vec<Self::Item></code>. The iterator produces a new Vec per iteration,
|
|||
|
and clones the iterator elements.</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">4</span>).combinations_with_replacement(<span class="number">2</span>);
|
|||
|
itertools::assert_equal(it, <span class="macro">vec!</span>[
|
|||
|
<span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">1</span>],
|
|||
|
<span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>],
|
|||
|
<span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">3</span>],
|
|||
|
<span class="macro">vec!</span>[<span class="number">2</span>, <span class="number">2</span>],
|
|||
|
<span class="macro">vec!</span>[<span class="number">2</span>, <span class="number">3</span>],
|
|||
|
<span class="macro">vec!</span>[<span class="number">3</span>, <span class="number">3</span>],
|
|||
|
]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.permutations" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1720-1726">source</a><h4 class="code-header">fn <a href="#method.permutations" class="fn">permutations</a>(self, k: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -> <a class="struct" href="structs/struct.Permutations.html" title="struct itertools::structs::Permutations">Permutations</a><Self> <a href="#" class="tooltip" data-notable-ty="Permutations<Self>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,</div></h4></section></summary><div class="docblock"><p>Return an iterator adaptor that iterates over all k-permutations of the
|
|||
|
elements from an iterator.</p>
|
|||
|
<p>Iterator element type is <code>Vec<Self::Item></code> with length <code>k</code>. The iterator
|
|||
|
produces a new Vec per iteration, and clones the iterator elements.</p>
|
|||
|
<p>If <code>k</code> is greater than the length of the input iterator, the resultant
|
|||
|
iterator adaptor will be empty.</p>
|
|||
|
<p>If you are looking for permutations with replacements,
|
|||
|
use <code>repeat_n(iter, k).multi_cartesian_product()</code> instead.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>perms = (<span class="number">5</span>..<span class="number">8</span>).permutations(<span class="number">2</span>);
|
|||
|
itertools::assert_equal(perms, <span class="macro">vec!</span>[
|
|||
|
<span class="macro">vec!</span>[<span class="number">5</span>, <span class="number">6</span>],
|
|||
|
<span class="macro">vec!</span>[<span class="number">5</span>, <span class="number">7</span>],
|
|||
|
<span class="macro">vec!</span>[<span class="number">6</span>, <span class="number">5</span>],
|
|||
|
<span class="macro">vec!</span>[<span class="number">6</span>, <span class="number">7</span>],
|
|||
|
<span class="macro">vec!</span>[<span class="number">7</span>, <span class="number">5</span>],
|
|||
|
<span class="macro">vec!</span>[<span class="number">7</span>, <span class="number">6</span>],
|
|||
|
]);</code></pre></div>
|
|||
|
<p>Note: Permutations does not take into account the equality of the iterated values.</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="macro">vec!</span>[<span class="number">2</span>, <span class="number">2</span>].into_iter().permutations(<span class="number">2</span>);
|
|||
|
itertools::assert_equal(it, <span class="macro">vec!</span>[
|
|||
|
<span class="macro">vec!</span>[<span class="number">2</span>, <span class="number">2</span>], <span class="comment">// Note: these are the same
|
|||
|
</span><span class="macro">vec!</span>[<span class="number">2</span>, <span class="number">2</span>], <span class="comment">// Note: these are the same
|
|||
|
</span>]);</code></pre></div>
|
|||
|
<p>Note: The source iterator is collected lazily, and will not be
|
|||
|
re-iterated if the permutations adaptor is completed and re-iterated.</p>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.powerset" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1757-1763">source</a><h4 class="code-header">fn <a href="#method.powerset" class="fn">powerset</a>(self) -> <a class="struct" href="structs/struct.Powerset.html" title="struct itertools::structs::Powerset">Powerset</a><Self> <a href="#" class="tooltip" data-notable-ty="Powerset<Self>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,</div></h4></section></summary><div class="docblock"><p>Return an iterator that iterates through the powerset of the elements from an
|
|||
|
iterator.</p>
|
|||
|
<p>Iterator element type is <code>Vec<Self::Item></code>. The iterator produces a new <code>Vec</code>
|
|||
|
per iteration, and clones the iterator elements.</p>
|
|||
|
<p>The powerset of a set contains all subsets including the empty set and the full
|
|||
|
input set. A powerset has length <em>2^n</em> where <em>n</em> is the length of the input
|
|||
|
set.</p>
|
|||
|
<p>Each <code>Vec</code> produced by this iterator represents a subset of the elements
|
|||
|
produced by the source iterator.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>sets = (<span class="number">1</span>..<span class="number">4</span>).powerset().collect::<Vec<<span class="kw">_</span>>>();
|
|||
|
itertools::assert_equal(sets, <span class="macro">vec!</span>[
|
|||
|
<span class="macro">vec!</span>[],
|
|||
|
<span class="macro">vec!</span>[<span class="number">1</span>],
|
|||
|
<span class="macro">vec!</span>[<span class="number">2</span>],
|
|||
|
<span class="macro">vec!</span>[<span class="number">3</span>],
|
|||
|
<span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>],
|
|||
|
<span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">3</span>],
|
|||
|
<span class="macro">vec!</span>[<span class="number">2</span>, <span class="number">3</span>],
|
|||
|
<span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>],
|
|||
|
]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.pad_using" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1782-1788">source</a><h4 class="code-header">fn <a href="#method.pad_using" class="fn">pad_using</a><F>(self, min: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>, f: F) -> <a class="struct" href="structs/struct.PadUsing.html" title="struct itertools::structs::PadUsing">PadUsing</a><Self, F> <a href="#" class="tooltip" data-notable-ty="PadUsing<Self, F>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -> Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>,</div></h4></section></summary><div class="docblock"><p>Return an iterator adaptor that pads the sequence to a minimum length of
|
|||
|
<code>min</code> by filling missing elements using a closure <code>f</code>.</p>
|
|||
|
<p>Iterator element type is <code>Self::Item</code>.</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">0</span>..<span class="number">5</span>).pad_using(<span class="number">10</span>, |i| <span class="number">2</span><span class="kw-2">*</span>i);
|
|||
|
itertools::assert_equal(it, <span class="macro">vec!</span>[<span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">10</span>, <span class="number">12</span>, <span class="number">14</span>, <span class="number">16</span>, <span class="number">18</span>]);
|
|||
|
|
|||
|
<span class="kw">let </span>it = (<span class="number">0</span>..<span class="number">10</span>).pad_using(<span class="number">5</span>, |i| <span class="number">2</span><span class="kw-2">*</span>i);
|
|||
|
itertools::assert_equal(it, <span class="macro">vec!</span>[<span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>, <span class="number">7</span>, <span class="number">8</span>, <span class="number">9</span>]);
|
|||
|
|
|||
|
<span class="kw">let </span>it = (<span class="number">0</span>..<span class="number">5</span>).pad_using(<span class="number">10</span>, |i| <span class="number">2</span><span class="kw-2">*</span>i).rev();
|
|||
|
itertools::assert_equal(it, <span class="macro">vec!</span>[<span class="number">18</span>, <span class="number">16</span>, <span class="number">14</span>, <span class="number">12</span>, <span class="number">10</span>, <span class="number">4</span>, <span class="number">3</span>, <span class="number">2</span>, <span class="number">1</span>, <span class="number">0</span>]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.with_position" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1809-1814">source</a><h4 class="code-header">fn <a href="#method.with_position" class="fn">with_position</a>(self) -> <a class="struct" href="structs/struct.WithPosition.html" title="struct itertools::structs::WithPosition">WithPosition</a><Self> <a href="#" class="tooltip" data-notable-ty="WithPosition<Self>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Return an iterator adaptor that combines each element with a <code>Position</code> to
|
|||
|
ease special-case handling of the first or last elements.</p>
|
|||
|
<p>Iterator element type is
|
|||
|
<a href="enum.Position.html" title="enum itertools::Position"><code>(Position, Self::Item)</code></a></p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::{Itertools, Position};
|
|||
|
|
|||
|
<span class="kw">let </span>it = (<span class="number">0</span>..<span class="number">4</span>).with_position();
|
|||
|
itertools::assert_equal(it,
|
|||
|
<span class="macro">vec!</span>[(Position::First, <span class="number">0</span>),
|
|||
|
(Position::Middle, <span class="number">1</span>),
|
|||
|
(Position::Middle, <span class="number">2</span>),
|
|||
|
(Position::Last, <span class="number">3</span>)]);
|
|||
|
|
|||
|
<span class="kw">let </span>it = (<span class="number">0</span>..<span class="number">1</span>).with_position();
|
|||
|
itertools::assert_equal(it, <span class="macro">vec!</span>[(Position::Only, <span class="number">0</span>)]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.positions" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1829-1835">source</a><h4 class="code-header">fn <a href="#method.positions" class="fn">positions</a><P>(self, predicate: P) -> <a class="struct" href="structs/struct.Positions.html" title="struct itertools::structs::Positions">Positions</a><Self, P> <a href="#" class="tooltip" data-notable-ty="Positions<Self, P>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
P: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>,</div></h4></section></summary><div class="docblock"><p>Return an iterator adaptor that yields the indices of all elements
|
|||
|
satisfying a predicate, counted from the start of the iterator.</p>
|
|||
|
<p>Equivalent to <code>iter.enumerate().filter(|(_, v)| predicate(*v)).map(|(i, _)| i)</code>.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>data = <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">6</span>, <span class="number">7</span>, <span class="number">9</span>];
|
|||
|
itertools::assert_equal(data.iter().positions(|v| v % <span class="number">2 </span>== <span class="number">0</span>), <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">4</span>, <span class="number">5</span>]);
|
|||
|
|
|||
|
itertools::assert_equal(data.iter().positions(|v| v % <span class="number">2 </span>== <span class="number">1</span>).rev(), <span class="macro">vec!</span>[<span class="number">7</span>, <span class="number">6</span>, <span class="number">3</span>, <span class="number">2</span>, <span class="number">0</span>]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.update" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1847-1853">source</a><h4 class="code-header">fn <a href="#method.update" class="fn">update</a><F>(self, updater: F) -> <a class="struct" href="structs/struct.Update.html" title="struct itertools::structs::Update">Update</a><Self, F> <a href="#" class="tooltip" data-notable-ty="Update<Self, F>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&mut Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>),</div></h4></section></summary><div class="docblock"><p>Return an iterator adaptor that applies a mutating function
|
|||
|
to each element before yielding it.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>input = <span class="macro">vec!</span>[<span class="macro">vec!</span>[<span class="number">1</span>], <span class="macro">vec!</span>[<span class="number">3</span>, <span class="number">2</span>, <span class="number">1</span>]];
|
|||
|
<span class="kw">let </span>it = input.into_iter().update(|<span class="kw-2">mut </span>v| v.push(<span class="number">0</span>));
|
|||
|
itertools::assert_equal(it, <span class="macro">vec!</span>[<span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">0</span>], <span class="macro">vec!</span>[<span class="number">3</span>, <span class="number">2</span>, <span class="number">1</span>, <span class="number">0</span>]]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.next_tuple" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1869-1875">source</a><h4 class="code-header">fn <a href="#method.next_tuple" class="fn">next_tuple</a><T>(&mut self) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><T><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = T::Item>,
|
|||
|
T: <a class="trait" href="traits/trait.HomogeneousTuple.html" title="trait itertools::traits::HomogeneousTuple">HomogeneousTuple</a>,</div></h4></section></summary><div class="docblock"><p>Advances the iterator and returns the next items grouped in a tuple of
|
|||
|
a specific size (up to 12).</p>
|
|||
|
<p>If there are enough elements to be grouped in a tuple, then the tuple is
|
|||
|
returned inside <code>Some</code>, otherwise <code>None</code> is returned.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span><span class="kw-2">mut </span>iter = <span class="number">1</span>..<span class="number">5</span>;
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>((<span class="number">1</span>, <span class="number">2</span>)), iter.next_tuple());</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.collect_tuple" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1895-1907">source</a><h4 class="code-header">fn <a href="#method.collect_tuple" class="fn">collect_tuple</a><T>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><T><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = T::Item>,
|
|||
|
T: <a class="trait" href="traits/trait.HomogeneousTuple.html" title="trait itertools::traits::HomogeneousTuple">HomogeneousTuple</a>,</div></h4></section></summary><div class="docblock"><p>Collects all items from the iterator into a tuple of a specific size
|
|||
|
(up to 12).</p>
|
|||
|
<p>If the number of elements inside the iterator is <strong>exactly</strong> equal to
|
|||
|
the tuple size, then the tuple is returned inside <code>Some</code>, otherwise
|
|||
|
<code>None</code> is returned.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>iter = <span class="number">1</span>..<span class="number">3</span>;
|
|||
|
|
|||
|
<span class="kw">if let </span><span class="prelude-val">Some</span>((x, y)) = iter.collect_tuple() {
|
|||
|
<span class="macro">assert_eq!</span>((x, y), (<span class="number">1</span>, <span class="number">2</span>))
|
|||
|
} <span class="kw">else </span>{
|
|||
|
<span class="macro">panic!</span>(<span class="string">"Expected two elements"</span>)
|
|||
|
}</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.find_position" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1919-1924">source</a><h4 class="code-header">fn <a href="#method.find_position" class="fn">find_position</a><P>(&mut self, pred: P) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><(<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>, Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>)><div class="where">where
|
|||
|
P: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>,</div></h4></section></summary><div class="docblock"><p>Find the position and value of the first element satisfying a predicate.</p>
|
|||
|
<p>The iterator is not advanced past the first element found.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>text = <span class="string">"Hα"</span>;
|
|||
|
<span class="macro">assert_eq!</span>(text.chars().find_position(|ch| ch.is_lowercase()), <span class="prelude-val">Some</span>((<span class="number">1</span>, <span class="string">'α'</span>)));</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.find_or_last" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1937-1952">source</a><h4 class="code-header">fn <a href="#method.find_or_last" class="fn">find_or_last</a><P>(self, predicate: P) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
P: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>,</div></h4></section></summary><div class="docblock"><p>Find the value of the first element satisfying a predicate or return the last element, if any.</p>
|
|||
|
<p>The iterator is not advanced past the first element found.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>numbers = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>];
|
|||
|
<span class="macro">assert_eq!</span>(numbers.iter().find_or_last(|&&x| x > <span class="number">5</span>), <span class="prelude-val">Some</span>(<span class="kw-2">&</span><span class="number">4</span>));
|
|||
|
<span class="macro">assert_eq!</span>(numbers.iter().find_or_last(|&&x| x > <span class="number">2</span>), <span class="prelude-val">Some</span>(<span class="kw-2">&</span><span class="number">3</span>));
|
|||
|
<span class="macro">assert_eq!</span>(std::iter::empty::<i32>().find_or_last(|<span class="kw-2">&</span>x| x > <span class="number">5</span>), <span class="prelude-val">None</span>);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.find_or_first" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#1965-1976">source</a><h4 class="code-header">fn <a href="#method.find_or_first" class="fn">find_or_first</a><P>(self, predicate: P) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
P: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>,</div></h4></section></summary><div class="docblock"><p>Find the value of the first element satisfying a predicate or return the first element, if any.</p>
|
|||
|
<p>The iterator is not advanced past the first element found.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>numbers = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>];
|
|||
|
<span class="macro">assert_eq!</span>(numbers.iter().find_or_first(|&&x| x > <span class="number">5</span>), <span class="prelude-val">Some</span>(<span class="kw-2">&</span><span class="number">1</span>));
|
|||
|
<span class="macro">assert_eq!</span>(numbers.iter().find_or_first(|&&x| x > <span class="number">2</span>), <span class="prelude-val">Some</span>(<span class="kw-2">&</span><span class="number">3</span>));
|
|||
|
<span class="macro">assert_eq!</span>(std::iter::empty::<i32>().find_or_first(|<span class="kw-2">&</span>x| x > <span class="number">5</span>), <span class="prelude-val">None</span>);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.contains" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2002-2009">source</a><h4 class="code-header">fn <a href="#method.contains" class="fn">contains</a><Q>(&mut self, query: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&Q</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><Q>,
|
|||
|
Q: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a>,</div></h4></section></summary><div class="docblock"><p>Returns <code>true</code> if the given item is present in this iterator.</p>
|
|||
|
<p>This method is short-circuiting. If the given item is present in this
|
|||
|
iterator, this method will consume the iterator up-to-and-including
|
|||
|
the item. If the given item is not present in this iterator, the
|
|||
|
iterator will be exhausted.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="attr">#[derive(PartialEq, Debug)]
|
|||
|
</span><span class="kw">enum </span>Enum { A, B, C, D, E, }
|
|||
|
|
|||
|
<span class="kw">let </span><span class="kw-2">mut </span>iter = <span class="macro">vec!</span>[Enum::A, Enum::B, Enum::C, Enum::D].into_iter();
|
|||
|
|
|||
|
<span class="comment">// search `iter` for `B`
|
|||
|
</span><span class="macro">assert_eq!</span>(iter.contains(<span class="kw-2">&</span>Enum::B), <span class="bool-val">true</span>);
|
|||
|
<span class="comment">// `B` was found, so the iterator now rests at the item after `B` (i.e, `C`).
|
|||
|
</span><span class="macro">assert_eq!</span>(iter.next(), <span class="prelude-val">Some</span>(Enum::C));
|
|||
|
|
|||
|
<span class="comment">// search `iter` for `E`
|
|||
|
</span><span class="macro">assert_eq!</span>(iter.contains(<span class="kw-2">&</span>Enum::E), <span class="bool-val">false</span>);
|
|||
|
<span class="comment">// `E` wasn't found, so `iter` is now exhausted
|
|||
|
</span><span class="macro">assert_eq!</span>(iter.next(), <span class="prelude-val">None</span>);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.all_equal" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2027-2036">source</a><h4 class="code-header">fn <a href="#method.all_equal" class="fn">all_equal</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a>,</div></h4></section></summary><div class="docblock"><p>Check whether all elements compare equal.</p>
|
|||
|
<p>Empty iterators are considered to have equal elements:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>data = <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">3</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">5</span>];
|
|||
|
<span class="macro">assert!</span>(!data.iter().all_equal());
|
|||
|
<span class="macro">assert!</span>(data[<span class="number">0</span>..<span class="number">3</span>].iter().all_equal());
|
|||
|
<span class="macro">assert!</span>(data[<span class="number">3</span>..<span class="number">5</span>].iter().all_equal());
|
|||
|
<span class="macro">assert!</span>(data[<span class="number">5</span>..<span class="number">8</span>].iter().all_equal());
|
|||
|
|
|||
|
<span class="kw">let </span>data : <span class="prelude-ty">Option</span><usize> = <span class="prelude-val">None</span>;
|
|||
|
<span class="macro">assert!</span>(data.into_iter().all_equal());</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.all_equal_value" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2056-2068">source</a><h4 class="code-header">fn <a href="#method.all_equal_value" class="fn">all_equal_value</a>(
|
|||
|
&mut self
|
|||
|
) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><(Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>)>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a>,</div></h4></section></summary><div class="docblock"><p>If there are elements and they are all equal, return a single copy of that element.
|
|||
|
If there are no elements, return an Error containing None.
|
|||
|
If there are elements and they are not all equal, return a tuple containing the first
|
|||
|
two non-equal elements found.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>data = <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">3</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">5</span>];
|
|||
|
<span class="macro">assert_eq!</span>(data.iter().all_equal_value(), <span class="prelude-val">Err</span>(<span class="prelude-val">Some</span>((<span class="kw-2">&</span><span class="number">1</span>, <span class="kw-2">&</span><span class="number">2</span>))));
|
|||
|
<span class="macro">assert_eq!</span>(data[<span class="number">0</span>..<span class="number">3</span>].iter().all_equal_value(), <span class="prelude-val">Ok</span>(<span class="kw-2">&</span><span class="number">1</span>));
|
|||
|
<span class="macro">assert_eq!</span>(data[<span class="number">3</span>..<span class="number">5</span>].iter().all_equal_value(), <span class="prelude-val">Ok</span>(<span class="kw-2">&</span><span class="number">2</span>));
|
|||
|
<span class="macro">assert_eq!</span>(data[<span class="number">5</span>..<span class="number">8</span>].iter().all_equal_value(), <span class="prelude-val">Ok</span>(<span class="kw-2">&</span><span class="number">3</span>));
|
|||
|
|
|||
|
<span class="kw">let </span>data : <span class="prelude-ty">Option</span><usize> = <span class="prelude-val">None</span>;
|
|||
|
<span class="macro">assert_eq!</span>(data.into_iter().all_equal_value(), <span class="prelude-val">Err</span>(<span class="prelude-val">None</span>));</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.all_unique" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2086-2093">source</a><h4 class="code-header">fn <a href="#method.all_unique" class="fn">all_unique</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a>,</div></h4></section></summary><div class="docblock"><p>Check whether all elements are unique (non equal).</p>
|
|||
|
<p>Empty iterators are considered to have unique elements:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>data = <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">1</span>, <span class="number">5</span>];
|
|||
|
<span class="macro">assert!</span>(!data.iter().all_unique());
|
|||
|
<span class="macro">assert!</span>(data[<span class="number">0</span>..<span class="number">4</span>].iter().all_unique());
|
|||
|
<span class="macro">assert!</span>(data[<span class="number">1</span>..<span class="number">6</span>].iter().all_unique());
|
|||
|
|
|||
|
<span class="kw">let </span>data : <span class="prelude-ty">Option</span><usize> = <span class="prelude-val">None</span>;
|
|||
|
<span class="macro">assert!</span>(data.into_iter().all_unique());</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.dropping" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2110-2118">source</a><h4 class="code-header">fn <a href="#method.dropping" class="fn">dropping</a>(self, n: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -> Self<div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Consume the first <code>n</code> elements from the iterator eagerly,
|
|||
|
and return the same iterator again.</p>
|
|||
|
<p>It works similarly to <em>.skip(</em> <code>n</code> <em>)</em> except it is eager and
|
|||
|
preserves the iterator type.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span><span class="kw-2">mut </span>iter = <span class="string">"αβγ"</span>.chars().dropping(<span class="number">2</span>);
|
|||
|
itertools::assert_equal(iter, <span class="string">"γ"</span>.chars());</code></pre></div>
|
|||
|
<p><em>Fusing notes: if the iterator is exhausted by dropping,
|
|||
|
the result of calling <code>.next()</code> again depends on the iterator implementation.</em></p>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.dropping_back" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2135-2143">source</a><h4 class="code-header">fn <a href="#method.dropping_back" class="fn">dropping_back</a>(self, n: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -> Self<div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/double_ended/trait.DoubleEndedIterator.html" title="trait core::iter::traits::double_ended::DoubleEndedIterator">DoubleEndedIterator</a>,</div></h4></section></summary><div class="docblock"><p>Consume the last <code>n</code> elements from the iterator eagerly,
|
|||
|
and return the same iterator again.</p>
|
|||
|
<p>This is only possible on double ended iterators. <code>n</code> may be
|
|||
|
larger than the number of elements.</p>
|
|||
|
<p>Note: This method is eager, dropping the back elements immediately and
|
|||
|
preserves the iterator type.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>init = <span class="macro">vec!</span>[<span class="number">0</span>, <span class="number">3</span>, <span class="number">6</span>, <span class="number">9</span>].into_iter().dropping_back(<span class="number">1</span>);
|
|||
|
itertools::assert_equal(init, <span class="macro">vec!</span>[<span class="number">0</span>, <span class="number">3</span>, <span class="number">6</span>]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.foreach" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2163-2169">source</a><h4 class="code-header">fn <a href="#method.foreach" class="fn">foreach</a><F>(self, f: F)<div class="where">where
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>),
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span><span>Deprecated since 0.8.0: Use .for_each() instead</span></div></span><div class="docblock"><p>Run the closure <code>f</code> eagerly on each element of the iterator.</p>
|
|||
|
<p>Consumes the iterator until its end.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::sync::mpsc::channel;
|
|||
|
<span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>(tx, rx) = channel();
|
|||
|
|
|||
|
<span class="comment">// use .foreach() to apply a function to each value -- sending it
|
|||
|
</span>(<span class="number">0</span>..<span class="number">5</span>).map(|x| x * <span class="number">2 </span>+ <span class="number">1</span>).foreach(|x| { tx.send(x).unwrap(); } );
|
|||
|
|
|||
|
drop(tx);
|
|||
|
|
|||
|
itertools::assert_equal(rx.iter(), <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>, <span class="number">9</span>]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.concat" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2184-2191">source</a><h4 class="code-header">fn <a href="#method.concat" class="fn">concat</a>(self) -> Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.Extend.html" title="trait core::iter::traits::collect::Extend">Extend</a><<<Self as <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a> as <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" title="type core::iter::traits::collect::IntoIterator::Item">Item</a>> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/default/trait.Default.html" title="trait core::default::Default">Default</a>,</div></h4></section></summary><div class="docblock"><p>Combine all an iterator’s elements into one element by using <a href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.Extend.html" title="trait core::iter::traits::collect::Extend"><code>Extend</code></a>.</p>
|
|||
|
<p>This combinator will extend the first item with each of the rest of the
|
|||
|
items of the iterator. If the iterator is empty, the default value of
|
|||
|
<code>I::Item</code> is returned.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>input = <span class="macro">vec!</span>[<span class="macro">vec!</span>[<span class="number">1</span>], <span class="macro">vec!</span>[<span class="number">2</span>, <span class="number">3</span>], <span class="macro">vec!</span>[<span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>]];
|
|||
|
<span class="macro">assert_eq!</span>(input.into_iter().concat(),
|
|||
|
<span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.collect_vec" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2196-2201">source</a><h4 class="code-header">fn <a href="#method.collect_vec" class="fn">collect_vec</a>(self) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p><code>.collect_vec()</code> is simply a type specialization of <a href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#method.collect" title="method core::iter::traits::iterator::Iterator::collect"><code>Iterator::collect</code></a>,
|
|||
|
for convenience.</p>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.try_collect" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2223-2229">source</a><h4 class="code-header">fn <a href="#method.try_collect" class="fn">try_collect</a><T, U, E>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><U, E><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, E>>,
|
|||
|
<a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><U, E>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.FromIterator.html" title="trait core::iter::traits::collect::FromIterator">FromIterator</a><<a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, E>>,</div></h4></section></summary><div class="docblock"><p><code>.try_collect()</code> is more convenient way of writing
|
|||
|
<code>.collect::<Result<_, _>>()</code></p>
|
|||
|
<h5 id="example-1"><a href="#example-1">Example</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::{fs, io};
|
|||
|
<span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">fn </span>process_dir_entries(entries: <span class="kw-2">&</span>[fs::DirEntry]) {
|
|||
|
<span class="comment">// ...
|
|||
|
</span>}
|
|||
|
|
|||
|
<span class="kw">fn </span>do_stuff() -> std::io::Result<()> {
|
|||
|
<span class="kw">let </span>entries: Vec<<span class="kw">_</span>> = fs::read_dir(<span class="string">"."</span>)<span class="question-mark">?</span>.try_collect()<span class="question-mark">?</span>;
|
|||
|
process_dir_entries(<span class="kw-2">&</span>entries);
|
|||
|
|
|||
|
<span class="prelude-val">Ok</span>(())
|
|||
|
}</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.set_from" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2247-2261">source</a><h4 class="code-header">fn <a href="#method.set_from" class="fn">set_from</a><'a, A: 'a, J>(&mut self, from: J) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&'a mut A</a>>,
|
|||
|
J: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a><Item = A>,</div></h4></section></summary><div class="docblock"><p>Assign to each reference in <code>self</code> from the <code>from</code> iterator,
|
|||
|
stopping at the shortest of the two iterators.</p>
|
|||
|
<p>The <code>from</code> iterator is queried for its next element before the <code>self</code>
|
|||
|
iterator, and if either is exhausted the method is done.</p>
|
|||
|
<p>Return the number of elements written.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span><span class="kw-2">mut </span>xs = [<span class="number">0</span>; <span class="number">4</span>];
|
|||
|
xs.iter_mut().set_from(<span class="number">1</span>..);
|
|||
|
<span class="macro">assert_eq!</span>(xs, [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.join" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2274-2292">source</a><h4 class="code-header">fn <a href="#method.join" class="fn">join</a>(&mut self, sep: &<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.str.html">str</a>) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/string/struct.String.html" title="struct alloc::string::String">String</a><div class="where">where
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a>,</div></h4></section></summary><div class="docblock"><p>Combine all iterator elements into one String, separated by <code>sep</code>.</p>
|
|||
|
<p>Use the <code>Display</code> implementation of each element.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>([<span class="string">"a"</span>, <span class="string">"b"</span>, <span class="string">"c"</span>].iter().join(<span class="string">", "</span>), <span class="string">"a, b, c"</span>);
|
|||
|
<span class="macro">assert_eq!</span>([<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>].iter().join(<span class="string">", "</span>), <span class="string">"1, 2, 3"</span>);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.format" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2309-2314">source</a><h4 class="code-header">fn <a href="#method.format" class="fn">format</a>(self, sep: &<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.str.html">str</a>) -> <a class="struct" href="structs/struct.Format.html" title="struct itertools::structs::Format">Format</a><'_, Self><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Format all iterator elements, separated by <code>sep</code>.</p>
|
|||
|
<p>All elements are formatted (any formatting trait)
|
|||
|
with <code>sep</code> inserted between each element.</p>
|
|||
|
<p><strong>Panics</strong> if the formatter helper is formatted more than once.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>data = [<span class="number">1.1</span>, <span class="number">2.71828</span>, -<span class="number">3.</span>];
|
|||
|
<span class="macro">assert_eq!</span>(
|
|||
|
<span class="macro">format!</span>(<span class="string">"{:.2}"</span>, data.iter().format(<span class="string">", "</span>)),
|
|||
|
<span class="string">"1.10, 2.72, -3.00"</span>);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.format_with" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2348-2354">source</a><h4 class="code-header">fn <a href="#method.format_with" class="fn">format_with</a><F>(self, sep: &<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.str.html">str</a>, format: F) -> <a class="struct" href="structs/struct.FormatWith.html" title="struct itertools::structs::FormatWith">FormatWith</a><'_, Self, F><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, &mut dyn <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&dyn <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a>) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a>) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a>,</div></h4></section></summary><div class="docblock"><p>Format all iterator elements, separated by <code>sep</code>.</p>
|
|||
|
<p>This is a customizable version of <a href="trait.Itertools.html#method.format" title="method itertools::Itertools::format"><code>.format()</code></a>.</p>
|
|||
|
<p>The supplied closure <code>format</code> is called once per iterator element,
|
|||
|
with two arguments: the element and a callback that takes a
|
|||
|
<code>&Display</code> value, i.e. any reference to type that implements <code>Display</code>.</p>
|
|||
|
<p>Using <code>&format_args!(...)</code> is the most versatile way to apply custom
|
|||
|
element formatting. The callback can be called multiple times if needed.</p>
|
|||
|
<p><strong>Panics</strong> if the formatter helper is formatted more than once.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>data = [<span class="number">1.1</span>, <span class="number">2.71828</span>, -<span class="number">3.</span>];
|
|||
|
<span class="kw">let </span>data_formatter = data.iter().format_with(<span class="string">", "</span>, |elt, f| f(<span class="kw-2">&</span><span class="macro">format_args!</span>(<span class="string">"{:.2}"</span>, elt)));
|
|||
|
<span class="macro">assert_eq!</span>(<span class="macro">format!</span>(<span class="string">"{}"</span>, data_formatter),
|
|||
|
<span class="string">"1.10, 2.72, -3.00"</span>);
|
|||
|
|
|||
|
<span class="comment">// .format_with() is recursively composable
|
|||
|
</span><span class="kw">let </span>matrix = [[<span class="number">1.</span>, <span class="number">2.</span>, <span class="number">3.</span>],
|
|||
|
[<span class="number">4.</span>, <span class="number">5.</span>, <span class="number">6.</span>]];
|
|||
|
<span class="kw">let </span>matrix_formatter = matrix.iter().format_with(<span class="string">"\n"</span>, |row, f| {
|
|||
|
f(<span class="kw-2">&</span>row.iter().format_with(<span class="string">", "</span>, |elt, g| g(<span class="kw-2">&</span>elt)))
|
|||
|
});
|
|||
|
<span class="macro">assert_eq!</span>(<span class="macro">format!</span>(<span class="string">"{}"</span>, matrix_formatter),
|
|||
|
<span class="string">"1, 2, 3\n4, 5, 6"</span>);
|
|||
|
|
|||
|
</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.fold_results" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2358-2364">source</a><h4 class="code-header">fn <a href="#method.fold_results" class="fn">fold_results</a><A, E, B, F>(&mut self, start: B, f: F) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><B, E><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><A, E>>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(B, A) -> B,</div></h4></section></summary><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span><span>Deprecated since 0.10.0: Use .fold_ok() instead</span></div></span><div class="docblock"><p>See <a href="trait.Itertools.html#method.fold_ok" title="method itertools::Itertools::fold_ok"><code>.fold_ok()</code></a>.</p>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.fold_ok" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2410-2422">source</a><h4 class="code-header">fn <a href="#method.fold_ok" class="fn">fold_ok</a><A, E, B, F>(&mut self, start: B, f: F) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><B, E><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><A, E>>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(B, A) -> B,</div></h4></section></summary><div class="docblock"><p>Fold <code>Result</code> values from an iterator.</p>
|
|||
|
<p>Only <code>Ok</code> values are folded. If no error is encountered, the folded
|
|||
|
value is returned inside <code>Ok</code>. Otherwise, the operation terminates
|
|||
|
and returns the first <code>Err</code> value it encounters. No iterator elements are
|
|||
|
consumed after the first error.</p>
|
|||
|
<p>The first accumulator value is the <code>start</code> parameter.
|
|||
|
Each iteration passes the accumulator value and the next value inside <code>Ok</code>
|
|||
|
to the fold function <code>f</code> and its return value becomes the new accumulator value.</p>
|
|||
|
<p>For example the sequence <em>Ok(1), Ok(2), Ok(3)</em> will result in a
|
|||
|
computation like this:</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span><span class="kw-2">mut </span>accum = start;
|
|||
|
accum = f(accum, <span class="number">1</span>);
|
|||
|
accum = f(accum, <span class="number">2</span>);
|
|||
|
accum = f(accum, <span class="number">3</span>);</code></pre></div>
|
|||
|
<p>With a <code>start</code> value of 0 and an addition as folding function,
|
|||
|
this effectively results in <em>((0 + 1) + 2) + 3</em></p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ops::Add;
|
|||
|
<span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>values = [<span class="number">1</span>, <span class="number">2</span>, -<span class="number">2</span>, -<span class="number">1</span>, <span class="number">2</span>, <span class="number">1</span>];
|
|||
|
<span class="macro">assert_eq!</span>(
|
|||
|
values.iter()
|
|||
|
.map(<span class="prelude-val">Ok</span>::<<span class="kw">_</span>, ()>)
|
|||
|
.fold_ok(<span class="number">0</span>, Add::add),
|
|||
|
<span class="prelude-val">Ok</span>(<span class="number">3</span>)
|
|||
|
);
|
|||
|
<span class="macro">assert!</span>(
|
|||
|
values.iter()
|
|||
|
.map(|<span class="kw-2">&</span>x| <span class="kw">if </span>x >= <span class="number">0 </span>{ <span class="prelude-val">Ok</span>(x) } <span class="kw">else </span>{ <span class="prelude-val">Err</span>(<span class="string">"Negative number"</span>) })
|
|||
|
.fold_ok(<span class="number">0</span>, Add::add)
|
|||
|
.is_err()
|
|||
|
);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.fold_options" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2443-2455">source</a><h4 class="code-header">fn <a href="#method.fold_options" class="fn">fold_options</a><A, B, F>(&mut self, start: B, f: F) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><B><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><A>>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(B, A) -> B,</div></h4></section></summary><div class="docblock"><p>Fold <code>Option</code> values from an iterator.</p>
|
|||
|
<p>Only <code>Some</code> values are folded. If no <code>None</code> is encountered, the folded
|
|||
|
value is returned inside <code>Some</code>. Otherwise, the operation terminates
|
|||
|
and returns <code>None</code>. No iterator elements are consumed after the <code>None</code>.</p>
|
|||
|
<p>This is the <code>Option</code> equivalent to <a href="trait.Itertools.html#method.fold_ok" title="method itertools::Itertools::fold_ok"><code>fold_ok</code></a>.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ops::Add;
|
|||
|
<span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span><span class="kw-2">mut </span>values = <span class="macro">vec!</span>[<span class="prelude-val">Some</span>(<span class="number">1</span>), <span class="prelude-val">Some</span>(<span class="number">2</span>), <span class="prelude-val">Some</span>(-<span class="number">2</span>)].into_iter();
|
|||
|
<span class="macro">assert_eq!</span>(values.fold_options(<span class="number">5</span>, Add::add), <span class="prelude-val">Some</span>(<span class="number">5 </span>+ <span class="number">1 </span>+ <span class="number">2 </span>- <span class="number">2</span>));
|
|||
|
|
|||
|
<span class="kw">let </span><span class="kw-2">mut </span>more_values = <span class="macro">vec!</span>[<span class="prelude-val">Some</span>(<span class="number">2</span>), <span class="prelude-val">None</span>, <span class="prelude-val">Some</span>(<span class="number">0</span>)].into_iter();
|
|||
|
<span class="macro">assert!</span>(more_values.fold_options(<span class="number">0</span>, Add::add).is_none());
|
|||
|
<span class="macro">assert_eq!</span>(more_values.next().unwrap(), <span class="prelude-val">Some</span>(<span class="number">0</span>));</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.fold1" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2470-2476">source</a><h4 class="code-header">fn <a href="#method.fold1" class="fn">fold1</a><F>(self, f: F) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>><div class="where">where
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span><span>Deprecated since 0.10.2: Use <code>Iterator::reduce</code> instead</span></div></span><div class="docblock"><p>Accumulator of the elements in the iterator.</p>
|
|||
|
<p>Like <code>.fold()</code>, without a base case. If the iterator is
|
|||
|
empty, return <code>None</code>. With just one element, return it.
|
|||
|
Otherwise elements are accumulated in sequence using the closure <code>f</code>.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>((<span class="number">0</span>..<span class="number">10</span>).fold1(|x, y| x + y).unwrap_or(<span class="number">0</span>), <span class="number">45</span>);
|
|||
|
<span class="macro">assert_eq!</span>((<span class="number">0</span>..<span class="number">0</span>).fold1(|x, y| x * y), <span class="prelude-val">None</span>);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.tree_fold1" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2537-2598">source</a><h4 class="code-header">fn <a href="#method.tree_fold1" class="fn">tree_fold1</a><F>(self, f: F) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>><div class="where">where
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Accumulate the elements in the iterator in a tree-like manner.</p>
|
|||
|
<p>You can think of it as, while there’s more than one item, repeatedly
|
|||
|
combining adjacent items. It does so in bottom-up-merge-sort order,
|
|||
|
however, so that it needs only logarithmic stack space.</p>
|
|||
|
<p>This produces a call tree like the following (where the calls under
|
|||
|
an item are done after reading that item):</p>
|
|||
|
<div class="example-wrap"><pre class="language-text"><code>1 2 3 4 5 6 7
|
|||
|
│ │ │ │ │ │ │
|
|||
|
└─f └─f └─f │
|
|||
|
│ │ │ │
|
|||
|
└───f └─f
|
|||
|
│ │
|
|||
|
└─────f
|
|||
|
</code></pre></div>
|
|||
|
<p>Which, for non-associative functions, will typically produce a different
|
|||
|
result than the linear call tree used by <a href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#method.reduce" title="method core::iter::traits::iterator::Iterator::reduce"><code>Iterator::reduce</code></a>:</p>
|
|||
|
<div class="example-wrap"><pre class="language-text"><code>1 2 3 4 5 6 7
|
|||
|
│ │ │ │ │ │ │
|
|||
|
└─f─f─f─f─f─f
|
|||
|
</code></pre></div>
|
|||
|
<p>If <code>f</code> is associative you should also decide carefully:</p>
|
|||
|
<ul>
|
|||
|
<li>if <code>f</code> is a trivial operation like <code>u32::wrapping_add</code>, prefer the normal
|
|||
|
<a href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#method.reduce" title="method core::iter::traits::iterator::Iterator::reduce"><code>Iterator::reduce</code></a> instead since it will most likely result in the generation of simpler
|
|||
|
code because the compiler is able to optimize it</li>
|
|||
|
<li>otherwise if <code>f</code> is non-trivial like <code>format!</code>, you should use <code>tree_fold1</code> since it
|
|||
|
reduces the number of operations from <code>O(n)</code> to <code>O(ln(n))</code></li>
|
|||
|
</ul>
|
|||
|
<p>Here “non-trivial” means:</p>
|
|||
|
<ul>
|
|||
|
<li>any allocating operation</li>
|
|||
|
<li>any function that is a composition of many operations</li>
|
|||
|
</ul>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="comment">// The same tree as above
|
|||
|
</span><span class="kw">let </span>num_strings = (<span class="number">1</span>..<span class="number">8</span>).map(|x| x.to_string());
|
|||
|
<span class="macro">assert_eq!</span>(num_strings.tree_fold1(|x, y| <span class="macro">format!</span>(<span class="string">"f({}, {})"</span>, x, y)),
|
|||
|
<span class="prelude-val">Some</span>(String::from(<span class="string">"f(f(f(1, 2), f(3, 4)), f(f(5, 6), 7))"</span>)));
|
|||
|
|
|||
|
<span class="comment">// Like fold1, an empty iterator produces None
|
|||
|
</span><span class="macro">assert_eq!</span>((<span class="number">0</span>..<span class="number">0</span>).tree_fold1(|x, y| x * y), <span class="prelude-val">None</span>);
|
|||
|
|
|||
|
<span class="comment">// tree_fold1 matches fold1 for associative operations...
|
|||
|
</span><span class="macro">assert_eq!</span>((<span class="number">0</span>..<span class="number">10</span>).tree_fold1(|x, y| x + y),
|
|||
|
(<span class="number">0</span>..<span class="number">10</span>).fold1(|x, y| x + y));
|
|||
|
<span class="comment">// ...but not for non-associative ones
|
|||
|
</span><span class="macro">assert_ne!</span>((<span class="number">0</span>..<span class="number">10</span>).tree_fold1(|x, y| x - y),
|
|||
|
(<span class="number">0</span>..<span class="number">10</span>).fold1(|x, y| x - y));</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.fold_while" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2639-2659">source</a><h4 class="code-header">fn <a href="#method.fold_while" class="fn">fold_while</a><B, F>(&mut self, init: B, f: F) -> <a class="enum" href="enum.FoldWhile.html" title="enum itertools::FoldWhile">FoldWhile</a><B><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(B, Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="enum" href="enum.FoldWhile.html" title="enum itertools::FoldWhile">FoldWhile</a><B>,</div></h4></section></summary><div class="docblock"><p>An iterator method that applies a function, producing a single, final value.</p>
|
|||
|
<p><code>fold_while()</code> is basically equivalent to <a href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#method.fold" title="method core::iter::traits::iterator::Iterator::fold"><code>Iterator::fold</code></a> but with additional support for
|
|||
|
early exit via short-circuiting.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
<span class="kw">use </span>itertools::FoldWhile::{Continue, Done};
|
|||
|
|
|||
|
<span class="kw">let </span>numbers = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>, <span class="number">7</span>, <span class="number">8</span>, <span class="number">9</span>, <span class="number">10</span>];
|
|||
|
|
|||
|
<span class="kw">let </span><span class="kw-2">mut </span>result = <span class="number">0</span>;
|
|||
|
|
|||
|
<span class="comment">// for loop:
|
|||
|
</span><span class="kw">for </span>i <span class="kw">in </span><span class="kw-2">&</span>numbers {
|
|||
|
<span class="kw">if </span><span class="kw-2">*</span>i > <span class="number">5 </span>{
|
|||
|
<span class="kw">break</span>;
|
|||
|
}
|
|||
|
result = result + i;
|
|||
|
}
|
|||
|
|
|||
|
<span class="comment">// fold:
|
|||
|
</span><span class="kw">let </span>result2 = numbers.iter().fold(<span class="number">0</span>, |acc, x| {
|
|||
|
<span class="kw">if </span><span class="kw-2">*</span>x > <span class="number">5 </span>{ acc } <span class="kw">else </span>{ acc + x }
|
|||
|
});
|
|||
|
|
|||
|
<span class="comment">// fold_while:
|
|||
|
</span><span class="kw">let </span>result3 = numbers.iter().fold_while(<span class="number">0</span>, |acc, x| {
|
|||
|
<span class="kw">if </span><span class="kw-2">*</span>x > <span class="number">5 </span>{ Done(acc) } <span class="kw">else </span>{ Continue(acc + x) }
|
|||
|
}).into_inner();
|
|||
|
|
|||
|
<span class="comment">// they're the same
|
|||
|
</span><span class="macro">assert_eq!</span>(result, result2);
|
|||
|
<span class="macro">assert_eq!</span>(result2, result3);</code></pre></div>
|
|||
|
<p>The big difference between the computations of <code>result2</code> and <code>result3</code> is that while
|
|||
|
<code>fold()</code> called the provided closure for every item of the callee iterator,
|
|||
|
<code>fold_while()</code> actually stopped iterating as soon as it encountered <code>Fold::Done(_)</code>.</p>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.sum1" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2682-2688">source</a><h4 class="code-header">fn <a href="#method.sum1" class="fn">sum1</a><S>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><S><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
S: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/accum/trait.Sum.html" title="trait core::iter::traits::accum::Sum">Sum</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>>,</div></h4></section></summary><div class="docblock"><p>Iterate over the entire iterator and add all the elements.</p>
|
|||
|
<p>An empty iterator returns <code>None</code>, otherwise <code>Some(sum)</code>.</p>
|
|||
|
<h5 id="panics"><a href="#panics">Panics</a></h5>
|
|||
|
<p>When calling <code>sum1()</code> and a primitive integer type is being returned, this
|
|||
|
method will panic if the computation overflows and debug assertions are
|
|||
|
enabled.</p>
|
|||
|
<h5 id="examples"><a href="#examples">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>empty_sum = (<span class="number">1</span>..<span class="number">1</span>).sum1::<i32>();
|
|||
|
<span class="macro">assert_eq!</span>(empty_sum, <span class="prelude-val">None</span>);
|
|||
|
|
|||
|
<span class="kw">let </span>nonempty_sum = (<span class="number">1</span>..<span class="number">11</span>).sum1::<i32>();
|
|||
|
<span class="macro">assert_eq!</span>(nonempty_sum, <span class="prelude-val">Some</span>(<span class="number">55</span>));</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.product1" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2710-2716">source</a><h4 class="code-header">fn <a href="#method.product1" class="fn">product1</a><P>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><P><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
P: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/accum/trait.Product.html" title="trait core::iter::traits::accum::Product">Product</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>>,</div></h4></section></summary><div class="docblock"><p>Iterate over the entire iterator and multiply all the elements.</p>
|
|||
|
<p>An empty iterator returns <code>None</code>, otherwise <code>Some(product)</code>.</p>
|
|||
|
<h5 id="panics-1"><a href="#panics-1">Panics</a></h5>
|
|||
|
<p>When calling <code>product1()</code> and a primitive integer type is being returned,
|
|||
|
method will panic if the computation overflows and debug assertions are
|
|||
|
enabled.</p>
|
|||
|
<h5 id="examples-1"><a href="#examples-1">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>empty_product = (<span class="number">1</span>..<span class="number">1</span>).product1::<i32>();
|
|||
|
<span class="macro">assert_eq!</span>(empty_product, <span class="prelude-val">None</span>);
|
|||
|
|
|||
|
<span class="kw">let </span>nonempty_product = (<span class="number">1</span>..<span class="number">11</span>).product1::<i32>();
|
|||
|
<span class="macro">assert_eq!</span>(nonempty_product, <span class="prelude-val">Some</span>(<span class="number">3628800</span>));</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.sorted_unstable" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2738-2748">source</a><h4 class="code-header">fn <a href="#method.sorted_unstable" class="fn">sorted_unstable</a>(self) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/into_iter/struct.IntoIter.html" title="struct alloc::vec::into_iter::IntoIter">IntoIter</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>> <a href="#" class="tooltip" data-notable-ty="IntoIter<Self::Item>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>,</div></h4></section></summary><div class="docblock"><p>Sort all iterator elements into a new iterator in ascending order.</p>
|
|||
|
<p><strong>Note:</strong> This consumes the entire iterator, uses the
|
|||
|
<a href="https://doc.rust-lang.org/1.76.0/std/primitive.slice.html#method.sort_unstable" title="method slice::sort_unstable"><code>slice::sort_unstable</code></a> method and returns the result as a new
|
|||
|
iterator that owns its elements.</p>
|
|||
|
<p>This sort is unstable (i.e., may reorder equal elements).</p>
|
|||
|
<p>The sorted iterator, if directly collected to a <code>Vec</code>, is converted
|
|||
|
without any extra copying or allocation cost.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="comment">// sort the letters of the text in ascending order
|
|||
|
</span><span class="kw">let </span>text = <span class="string">"bdacfe"</span>;
|
|||
|
itertools::assert_equal(text.chars().sorted_unstable(),
|
|||
|
<span class="string">"abcdef"</span>.chars());</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.sorted_unstable_by" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2776-2784">source</a><h4 class="code-header">fn <a href="#method.sorted_unstable_by" class="fn">sorted_unstable_by</a><F>(self, cmp: F) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/into_iter/struct.IntoIter.html" title="struct alloc::vec::into_iter::IntoIter">IntoIter</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>> <a href="#" class="tooltip" data-notable-ty="IntoIter<Self::Item>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, &Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a>,</div></h4></section></summary><div class="docblock"><p>Sort all iterator elements into a new iterator in ascending order.</p>
|
|||
|
<p><strong>Note:</strong> This consumes the entire iterator, uses the
|
|||
|
<a href="https://doc.rust-lang.org/1.76.0/std/primitive.slice.html#method.sort_unstable_by" title="method slice::sort_unstable_by"><code>slice::sort_unstable_by</code></a> method and returns the result as a new
|
|||
|
iterator that owns its elements.</p>
|
|||
|
<p>This sort is unstable (i.e., may reorder equal elements).</p>
|
|||
|
<p>The sorted iterator, if directly collected to a <code>Vec</code>, is converted
|
|||
|
without any extra copying or allocation cost.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="comment">// sort people in descending order by age
|
|||
|
</span><span class="kw">let </span>people = <span class="macro">vec!</span>[(<span class="string">"Jane"</span>, <span class="number">20</span>), (<span class="string">"John"</span>, <span class="number">18</span>), (<span class="string">"Jill"</span>, <span class="number">30</span>), (<span class="string">"Jack"</span>, <span class="number">27</span>)];
|
|||
|
|
|||
|
<span class="kw">let </span>oldest_people_first = people
|
|||
|
.into_iter()
|
|||
|
.sorted_unstable_by(|a, b| Ord::cmp(<span class="kw-2">&</span>b.<span class="number">1</span>, <span class="kw-2">&</span>a.<span class="number">1</span>))
|
|||
|
.map(|(person, _age)| person);
|
|||
|
|
|||
|
itertools::assert_equal(oldest_people_first,
|
|||
|
<span class="macro">vec!</span>[<span class="string">"Jill"</span>, <span class="string">"Jack"</span>, <span class="string">"Jane"</span>, <span class="string">"John"</span>]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.sorted_unstable_by_key" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2812-2821">source</a><h4 class="code-header">fn <a href="#method.sorted_unstable_by_key" class="fn">sorted_unstable_by_key</a><K, F>(self, f: F) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/into_iter/struct.IntoIter.html" title="struct alloc::vec::into_iter::IntoIter">IntoIter</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>> <a href="#" class="tooltip" data-notable-ty="IntoIter<Self::Item>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> K,</div></h4></section></summary><div class="docblock"><p>Sort all iterator elements into a new iterator in ascending order.</p>
|
|||
|
<p><strong>Note:</strong> This consumes the entire iterator, uses the
|
|||
|
<a href="https://doc.rust-lang.org/1.76.0/std/primitive.slice.html#method.sort_unstable_by_key" title="method slice::sort_unstable_by_key"><code>slice::sort_unstable_by_key</code></a> method and returns the result as a new
|
|||
|
iterator that owns its elements.</p>
|
|||
|
<p>This sort is unstable (i.e., may reorder equal elements).</p>
|
|||
|
<p>The sorted iterator, if directly collected to a <code>Vec</code>, is converted
|
|||
|
without any extra copying or allocation cost.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="comment">// sort people in descending order by age
|
|||
|
</span><span class="kw">let </span>people = <span class="macro">vec!</span>[(<span class="string">"Jane"</span>, <span class="number">20</span>), (<span class="string">"John"</span>, <span class="number">18</span>), (<span class="string">"Jill"</span>, <span class="number">30</span>), (<span class="string">"Jack"</span>, <span class="number">27</span>)];
|
|||
|
|
|||
|
<span class="kw">let </span>oldest_people_first = people
|
|||
|
.into_iter()
|
|||
|
.sorted_unstable_by_key(|x| -x.<span class="number">1</span>)
|
|||
|
.map(|(person, _age)| person);
|
|||
|
|
|||
|
itertools::assert_equal(oldest_people_first,
|
|||
|
<span class="macro">vec!</span>[<span class="string">"Jill"</span>, <span class="string">"Jack"</span>, <span class="string">"Jane"</span>, <span class="string">"John"</span>]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.sorted" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2843-2853">source</a><h4 class="code-header">fn <a href="#method.sorted" class="fn">sorted</a>(self) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/into_iter/struct.IntoIter.html" title="struct alloc::vec::into_iter::IntoIter">IntoIter</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>> <a href="#" class="tooltip" data-notable-ty="IntoIter<Self::Item>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>,</div></h4></section></summary><div class="docblock"><p>Sort all iterator elements into a new iterator in ascending order.</p>
|
|||
|
<p><strong>Note:</strong> This consumes the entire iterator, uses the
|
|||
|
<a href="https://doc.rust-lang.org/1.76.0/std/primitive.slice.html#method.sort" title="method slice::sort"><code>slice::sort</code></a> method and returns the result as a new
|
|||
|
iterator that owns its elements.</p>
|
|||
|
<p>This sort is stable (i.e., does not reorder equal elements).</p>
|
|||
|
<p>The sorted iterator, if directly collected to a <code>Vec</code>, is converted
|
|||
|
without any extra copying or allocation cost.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="comment">// sort the letters of the text in ascending order
|
|||
|
</span><span class="kw">let </span>text = <span class="string">"bdacfe"</span>;
|
|||
|
itertools::assert_equal(text.chars().sorted(),
|
|||
|
<span class="string">"abcdef"</span>.chars());</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.sorted_by" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2881-2889">source</a><h4 class="code-header">fn <a href="#method.sorted_by" class="fn">sorted_by</a><F>(self, cmp: F) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/into_iter/struct.IntoIter.html" title="struct alloc::vec::into_iter::IntoIter">IntoIter</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>> <a href="#" class="tooltip" data-notable-ty="IntoIter<Self::Item>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, &Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a>,</div></h4></section></summary><div class="docblock"><p>Sort all iterator elements into a new iterator in ascending order.</p>
|
|||
|
<p><strong>Note:</strong> This consumes the entire iterator, uses the
|
|||
|
<a href="https://doc.rust-lang.org/1.76.0/std/primitive.slice.html#method.sort_by" title="method slice::sort_by"><code>slice::sort_by</code></a> method and returns the result as a new
|
|||
|
iterator that owns its elements.</p>
|
|||
|
<p>This sort is stable (i.e., does not reorder equal elements).</p>
|
|||
|
<p>The sorted iterator, if directly collected to a <code>Vec</code>, is converted
|
|||
|
without any extra copying or allocation cost.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="comment">// sort people in descending order by age
|
|||
|
</span><span class="kw">let </span>people = <span class="macro">vec!</span>[(<span class="string">"Jane"</span>, <span class="number">20</span>), (<span class="string">"John"</span>, <span class="number">18</span>), (<span class="string">"Jill"</span>, <span class="number">30</span>), (<span class="string">"Jack"</span>, <span class="number">30</span>)];
|
|||
|
|
|||
|
<span class="kw">let </span>oldest_people_first = people
|
|||
|
.into_iter()
|
|||
|
.sorted_by(|a, b| Ord::cmp(<span class="kw-2">&</span>b.<span class="number">1</span>, <span class="kw-2">&</span>a.<span class="number">1</span>))
|
|||
|
.map(|(person, _age)| person);
|
|||
|
|
|||
|
itertools::assert_equal(oldest_people_first,
|
|||
|
<span class="macro">vec!</span>[<span class="string">"Jill"</span>, <span class="string">"Jack"</span>, <span class="string">"Jane"</span>, <span class="string">"John"</span>]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.sorted_by_key" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2917-2926">source</a><h4 class="code-header">fn <a href="#method.sorted_by_key" class="fn">sorted_by_key</a><K, F>(self, f: F) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/into_iter/struct.IntoIter.html" title="struct alloc::vec::into_iter::IntoIter">IntoIter</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>> <a href="#" class="tooltip" data-notable-ty="IntoIter<Self::Item>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> K,</div></h4></section></summary><div class="docblock"><p>Sort all iterator elements into a new iterator in ascending order.</p>
|
|||
|
<p><strong>Note:</strong> This consumes the entire iterator, uses the
|
|||
|
<a href="https://doc.rust-lang.org/1.76.0/std/primitive.slice.html#method.sort_by_key" title="method slice::sort_by_key"><code>slice::sort_by_key</code></a> method and returns the result as a new
|
|||
|
iterator that owns its elements.</p>
|
|||
|
<p>This sort is stable (i.e., does not reorder equal elements).</p>
|
|||
|
<p>The sorted iterator, if directly collected to a <code>Vec</code>, is converted
|
|||
|
without any extra copying or allocation cost.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="comment">// sort people in descending order by age
|
|||
|
</span><span class="kw">let </span>people = <span class="macro">vec!</span>[(<span class="string">"Jane"</span>, <span class="number">20</span>), (<span class="string">"John"</span>, <span class="number">18</span>), (<span class="string">"Jill"</span>, <span class="number">30</span>), (<span class="string">"Jack"</span>, <span class="number">30</span>)];
|
|||
|
|
|||
|
<span class="kw">let </span>oldest_people_first = people
|
|||
|
.into_iter()
|
|||
|
.sorted_by_key(|x| -x.<span class="number">1</span>)
|
|||
|
.map(|(person, _age)| person);
|
|||
|
|
|||
|
itertools::assert_equal(oldest_people_first,
|
|||
|
<span class="macro">vec!</span>[<span class="string">"Jill"</span>, <span class="string">"Jack"</span>, <span class="string">"Jane"</span>, <span class="string">"John"</span>]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.sorted_by_cached_key" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2955-2964">source</a><h4 class="code-header">fn <a href="#method.sorted_by_cached_key" class="fn">sorted_by_cached_key</a><K, F>(self, f: F) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/into_iter/struct.IntoIter.html" title="struct alloc::vec::into_iter::IntoIter">IntoIter</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>> <a href="#" class="tooltip" data-notable-ty="IntoIter<Self::Item>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> K,</div></h4></section></summary><div class="docblock"><p>Sort all iterator elements into a new iterator in ascending order. The key function is
|
|||
|
called exactly once per key.</p>
|
|||
|
<p><strong>Note:</strong> This consumes the entire iterator, uses the
|
|||
|
<a href="https://doc.rust-lang.org/1.76.0/std/primitive.slice.html#method.sort_by_cached_key" title="method slice::sort_by_cached_key"><code>slice::sort_by_cached_key</code></a> method and returns the result as a new
|
|||
|
iterator that owns its elements.</p>
|
|||
|
<p>This sort is stable (i.e., does not reorder equal elements).</p>
|
|||
|
<p>The sorted iterator, if directly collected to a <code>Vec</code>, is converted
|
|||
|
without any extra copying or allocation cost.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="comment">// sort people in descending order by age
|
|||
|
</span><span class="kw">let </span>people = <span class="macro">vec!</span>[(<span class="string">"Jane"</span>, <span class="number">20</span>), (<span class="string">"John"</span>, <span class="number">18</span>), (<span class="string">"Jill"</span>, <span class="number">30</span>), (<span class="string">"Jack"</span>, <span class="number">30</span>)];
|
|||
|
|
|||
|
<span class="kw">let </span>oldest_people_first = people
|
|||
|
.into_iter()
|
|||
|
.sorted_by_cached_key(|x| -x.<span class="number">1</span>)
|
|||
|
.map(|(person, _age)| person);
|
|||
|
|
|||
|
itertools::assert_equal(oldest_people_first,
|
|||
|
<span class="macro">vec!</span>[<span class="string">"Jill"</span>, <span class="string">"Jack"</span>, <span class="string">"Jane"</span>, <span class="string">"John"</span>]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.k_smallest" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#2994-3002">source</a><h4 class="code-header">fn <a href="#method.k_smallest" class="fn">k_smallest</a>(self, k: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/into_iter/struct.IntoIter.html" title="struct alloc::vec::into_iter::IntoIter">IntoIter</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>> <a href="#" class="tooltip" data-notable-ty="IntoIter<Self::Item>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>,</div></h4></section></summary><div class="docblock"><p>Sort the k smallest elements into a new iterator, in ascending order.</p>
|
|||
|
<p><strong>Note:</strong> This consumes the entire iterator, and returns the result
|
|||
|
as a new iterator that owns its elements. If the input contains
|
|||
|
less than k elements, the result is equivalent to <code>self.sorted()</code>.</p>
|
|||
|
<p>This is guaranteed to use <code>k * sizeof(Self::Item) + O(1)</code> memory
|
|||
|
and <code>O(n log k)</code> time, with <code>n</code> the number of elements in the input.</p>
|
|||
|
<p>The sorted iterator, if directly collected to a <code>Vec</code>, is converted
|
|||
|
without any extra copying or allocation cost.</p>
|
|||
|
<p><strong>Note:</strong> This is functionally-equivalent to <code>self.sorted().take(k)</code>
|
|||
|
but much more efficient.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="comment">// A random permutation of 0..15
|
|||
|
</span><span class="kw">let </span>numbers = <span class="macro">vec!</span>[<span class="number">6</span>, <span class="number">9</span>, <span class="number">1</span>, <span class="number">14</span>, <span class="number">0</span>, <span class="number">4</span>, <span class="number">8</span>, <span class="number">7</span>, <span class="number">11</span>, <span class="number">2</span>, <span class="number">10</span>, <span class="number">3</span>, <span class="number">13</span>, <span class="number">12</span>, <span class="number">5</span>];
|
|||
|
|
|||
|
<span class="kw">let </span>five_smallest = numbers
|
|||
|
.into_iter()
|
|||
|
.k_smallest(<span class="number">5</span>);
|
|||
|
|
|||
|
itertools::assert_equal(five_smallest, <span class="number">0</span>..<span class="number">5</span>);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.partition_map" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3025-3041">source</a><h4 class="code-header">fn <a href="#method.partition_map" class="fn">partition_map</a><A, B, F, L, R>(self, predicate: F) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.tuple.html">(A, B)</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="enum" href="enum.Either.html" title="enum itertools::Either">Either</a><L, R>,
|
|||
|
A: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/default/trait.Default.html" title="trait core::default::Default">Default</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.Extend.html" title="trait core::iter::traits::collect::Extend">Extend</a><L>,
|
|||
|
B: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/default/trait.Default.html" title="trait core::default::Default">Default</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.Extend.html" title="trait core::iter::traits::collect::Extend">Extend</a><R>,</div></h4></section></summary><div class="docblock"><p>Collect all iterator elements into one of two
|
|||
|
partitions. Unlike <a href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#method.partition" title="method core::iter::traits::iterator::Iterator::partition"><code>Iterator::partition</code></a>, each partition may
|
|||
|
have a distinct type.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::{Itertools, Either};
|
|||
|
|
|||
|
<span class="kw">let </span>successes_and_failures = <span class="macro">vec!</span>[<span class="prelude-val">Ok</span>(<span class="number">1</span>), <span class="prelude-val">Err</span>(<span class="bool-val">false</span>), <span class="prelude-val">Err</span>(<span class="bool-val">true</span>), <span class="prelude-val">Ok</span>(<span class="number">2</span>)];
|
|||
|
|
|||
|
<span class="kw">let </span>(successes, failures): (Vec<<span class="kw">_</span>>, Vec<<span class="kw">_</span>>) = successes_and_failures
|
|||
|
.into_iter()
|
|||
|
.partition_map(|r| {
|
|||
|
<span class="kw">match </span>r {
|
|||
|
<span class="prelude-val">Ok</span>(v) => Either::Left(v),
|
|||
|
<span class="prelude-val">Err</span>(v) => Either::Right(v),
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(successes, [<span class="number">1</span>, <span class="number">2</span>]);
|
|||
|
<span class="macro">assert_eq!</span>(failures, [<span class="bool-val">false</span>, <span class="bool-val">true</span>]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.partition_result" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3058-3068">source</a><h4 class="code-header">fn <a href="#method.partition_result" class="fn">partition_result</a><A, B, T, E>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.tuple.html">(A, B)</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, E>> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
A: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/default/trait.Default.html" title="trait core::default::Default">Default</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.Extend.html" title="trait core::iter::traits::collect::Extend">Extend</a><T>,
|
|||
|
B: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/default/trait.Default.html" title="trait core::default::Default">Default</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.Extend.html" title="trait core::iter::traits::collect::Extend">Extend</a><E>,</div></h4></section></summary><div class="docblock"><p>Partition a sequence of <code>Result</code>s into one list of all the <code>Ok</code> elements
|
|||
|
and another list of all the <code>Err</code> elements.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>successes_and_failures = <span class="macro">vec!</span>[<span class="prelude-val">Ok</span>(<span class="number">1</span>), <span class="prelude-val">Err</span>(<span class="bool-val">false</span>), <span class="prelude-val">Err</span>(<span class="bool-val">true</span>), <span class="prelude-val">Ok</span>(<span class="number">2</span>)];
|
|||
|
|
|||
|
<span class="kw">let </span>(successes, failures): (Vec<<span class="kw">_</span>>, Vec<<span class="kw">_</span>>) = successes_and_failures
|
|||
|
.into_iter()
|
|||
|
.partition_result();
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(successes, [<span class="number">1</span>, <span class="number">2</span>]);
|
|||
|
<span class="macro">assert_eq!</span>(failures, [<span class="bool-val">false</span>, <span class="bool-val">true</span>]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.into_group_map" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3087-3093">source</a><h4 class="code-header">fn <a href="#method.into_group_map" class="fn">into_group_map</a><K, V>(self) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/collections/hash/map/struct.HashMap.html" title="struct std::collections::hash::map::HashMap">HashMap</a><K, <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><V>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.tuple.html">(K, V)</a>> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a>,</div></h4></section></summary><div class="docblock"><p>Return a <code>HashMap</code> of keys mapped to <code>Vec</code>s of values. Keys and values
|
|||
|
are taken from <code>(Key, Value)</code> tuple pairs yielded by the input iterator.</p>
|
|||
|
<p>Essentially a shorthand for <code>.into_grouping_map().collect::<Vec<_>>()</code>.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>data = <span class="macro">vec!</span>[(<span class="number">0</span>, <span class="number">10</span>), (<span class="number">2</span>, <span class="number">12</span>), (<span class="number">3</span>, <span class="number">13</span>), (<span class="number">0</span>, <span class="number">20</span>), (<span class="number">3</span>, <span class="number">33</span>), (<span class="number">2</span>, <span class="number">42</span>)];
|
|||
|
<span class="kw">let </span>lookup = data.into_iter().into_group_map();
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(lookup[<span class="kw-2">&</span><span class="number">0</span>], <span class="macro">vec!</span>[<span class="number">10</span>, <span class="number">20</span>]);
|
|||
|
<span class="macro">assert_eq!</span>(lookup.get(<span class="kw-2">&</span><span class="number">1</span>), <span class="prelude-val">None</span>);
|
|||
|
<span class="macro">assert_eq!</span>(lookup[<span class="kw-2">&</span><span class="number">2</span>], <span class="macro">vec!</span>[<span class="number">12</span>, <span class="number">42</span>]);
|
|||
|
<span class="macro">assert_eq!</span>(lookup[<span class="kw-2">&</span><span class="number">3</span>], <span class="macro">vec!</span>[<span class="number">13</span>, <span class="number">33</span>]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.into_group_map_by" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3123-3130">source</a><h4 class="code-header">fn <a href="#method.into_group_map_by" class="fn">into_group_map_by</a><K, V, F>(self, f: F) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/collections/hash/map/struct.HashMap.html" title="struct std::collections::hash::map::HashMap">HashMap</a><K, <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><V>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = V> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&V</a>) -> K,</div></h4></section></summary><div class="docblock"><p>Return an <code>Iterator</code> on a <code>HashMap</code>. Keys mapped to <code>Vec</code>s of values. The key is specified
|
|||
|
in the closure.</p>
|
|||
|
<p>Essentially a shorthand for <code>.into_grouping_map_by(f).collect::<Vec<_>>()</code>.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
<span class="kw">use </span>std::collections::HashMap;
|
|||
|
|
|||
|
<span class="kw">let </span>data = <span class="macro">vec!</span>[(<span class="number">0</span>, <span class="number">10</span>), (<span class="number">2</span>, <span class="number">12</span>), (<span class="number">3</span>, <span class="number">13</span>), (<span class="number">0</span>, <span class="number">20</span>), (<span class="number">3</span>, <span class="number">33</span>), (<span class="number">2</span>, <span class="number">42</span>)];
|
|||
|
<span class="kw">let </span>lookup: HashMap<u32,Vec<(u32, u32)>> =
|
|||
|
data.clone().into_iter().into_group_map_by(|a| a.<span class="number">0</span>);
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(lookup[<span class="kw-2">&</span><span class="number">0</span>], <span class="macro">vec!</span>[(<span class="number">0</span>,<span class="number">10</span>),(<span class="number">0</span>,<span class="number">20</span>)]);
|
|||
|
<span class="macro">assert_eq!</span>(lookup.get(<span class="kw-2">&</span><span class="number">1</span>), <span class="prelude-val">None</span>);
|
|||
|
<span class="macro">assert_eq!</span>(lookup[<span class="kw-2">&</span><span class="number">2</span>], <span class="macro">vec!</span>[(<span class="number">2</span>,<span class="number">12</span>), (<span class="number">2</span>,<span class="number">42</span>)]);
|
|||
|
<span class="macro">assert_eq!</span>(lookup[<span class="kw-2">&</span><span class="number">3</span>], <span class="macro">vec!</span>[(<span class="number">3</span>,<span class="number">13</span>), (<span class="number">3</span>,<span class="number">33</span>)]);
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(
|
|||
|
data.into_iter()
|
|||
|
.into_group_map_by(|x| x.<span class="number">0</span>)
|
|||
|
.into_iter()
|
|||
|
.map(|(key, values)| (key, values.into_iter().fold(<span class="number">0</span>,|acc, (<span class="kw">_</span>,v)| acc + v )))
|
|||
|
.collect::<HashMap<u32,u32>>()[<span class="kw-2">&</span><span class="number">0</span>],
|
|||
|
<span class="number">30</span>,
|
|||
|
);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.into_grouping_map" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3142-3148">source</a><h4 class="code-header">fn <a href="#method.into_grouping_map" class="fn">into_grouping_map</a><K, V>(self) -> <a class="struct" href="structs/struct.GroupingMap.html" title="struct itertools::structs::GroupingMap">GroupingMap</a><Self><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.tuple.html">(K, V)</a>> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a>,</div></h4></section></summary><div class="docblock"><p>Constructs a <code>GroupingMap</code> to be used later with one of the efficient
|
|||
|
group-and-fold operations it allows to perform.</p>
|
|||
|
<p>The input iterator must yield item in the form of <code>(K, V)</code> where the
|
|||
|
value of type <code>K</code> will be used as key to identify the groups and the
|
|||
|
value of type <code>V</code> as value for the folding operation.</p>
|
|||
|
<p>See <a href="structs/struct.GroupingMap.html" title="struct itertools::structs::GroupingMap"><code>GroupingMap</code></a> for more informations
|
|||
|
on what operations are available.</p>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.into_grouping_map_by" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3159-3166">source</a><h4 class="code-header">fn <a href="#method.into_grouping_map_by" class="fn">into_grouping_map_by</a><K, V, F>(self, key_mapper: F) -> <a class="type" href="structs/type.GroupingMapBy.html" title="type itertools::structs::GroupingMapBy">GroupingMapBy</a><Self, F><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a><Item = V> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&V</a>) -> K,</div></h4></section></summary><div class="docblock"><p>Constructs a <code>GroupingMap</code> to be used later with one of the efficient
|
|||
|
group-and-fold operations it allows to perform.</p>
|
|||
|
<p>The values from this iterator will be used as values for the folding operation
|
|||
|
while the keys will be obtained from the values by calling <code>key_mapper</code>.</p>
|
|||
|
<p>See <a href="structs/struct.GroupingMap.html" title="struct itertools::structs::GroupingMap"><code>GroupingMap</code></a> for more informations
|
|||
|
on what operations are available.</p>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.min_set" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3191-3197">source</a><h4 class="code-header">fn <a href="#method.min_set" class="fn">min_set</a>(self) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>,</div></h4></section></summary><div class="docblock"><p>Return all minimum elements of an iterator.</p>
|
|||
|
<h5 id="examples-2"><a href="#examples-2">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>a: [i32; <span class="number">0</span>] = [];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().min_set(), Vec::<<span class="kw-2">&</span>i32>::new());
|
|||
|
|
|||
|
<span class="kw">let </span>a = [<span class="number">1</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().min_set(), <span class="macro">vec!</span>[<span class="kw-2">&</span><span class="number">1</span>]);
|
|||
|
|
|||
|
<span class="kw">let </span>a = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().min_set(), <span class="macro">vec!</span>[<span class="kw-2">&</span><span class="number">1</span>]);
|
|||
|
|
|||
|
<span class="kw">let </span>a = [<span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().min_set(), <span class="macro">vec!</span>[<span class="kw-2">&</span><span class="number">1</span>, <span class="kw-2">&</span><span class="number">1</span>, <span class="kw-2">&</span><span class="number">1</span>, <span class="kw-2">&</span><span class="number">1</span>]);</code></pre></div>
|
|||
|
<p>The elements can be floats but no particular result is guaranteed
|
|||
|
if an element is NaN.</p>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.min_set_by" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3224-3230">source</a><h4 class="code-header">fn <a href="#method.min_set_by" class="fn">min_set_by</a><F>(self, compare: F) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, &Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a>,</div></h4></section></summary><div class="docblock"><p>Return all minimum elements of an iterator, as determined by
|
|||
|
the specified function.</p>
|
|||
|
<h5 id="examples-3"><a href="#examples-3">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>a: [(i32, i32); <span class="number">0</span>] = [];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().min_set_by(|<span class="kw">_</span>, <span class="kw">_</span>| Ordering::Equal), Vec::<<span class="kw-2">&</span>(i32, i32)>::new());
|
|||
|
|
|||
|
<span class="kw">let </span>a = [(<span class="number">1</span>, <span class="number">2</span>)];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().min_set_by(|&&(k1,<span class="kw">_</span>), &&(k2, <span class="kw">_</span>)| k1.cmp(<span class="kw-2">&</span>k2)), <span class="macro">vec!</span>[<span class="kw-2">&</span>(<span class="number">1</span>, <span class="number">2</span>)]);
|
|||
|
|
|||
|
<span class="kw">let </span>a = [(<span class="number">1</span>, <span class="number">2</span>), (<span class="number">2</span>, <span class="number">2</span>), (<span class="number">3</span>, <span class="number">9</span>), (<span class="number">4</span>, <span class="number">8</span>), (<span class="number">5</span>, <span class="number">9</span>)];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().min_set_by(|&&(<span class="kw">_</span>,k1), &&(<span class="kw">_</span>,k2)| k1.cmp(<span class="kw-2">&</span>k2)), <span class="macro">vec!</span>[<span class="kw-2">&</span>(<span class="number">1</span>, <span class="number">2</span>), <span class="kw-2">&</span>(<span class="number">2</span>, <span class="number">2</span>)]);
|
|||
|
|
|||
|
<span class="kw">let </span>a = [(<span class="number">1</span>, <span class="number">2</span>), (<span class="number">1</span>, <span class="number">3</span>), (<span class="number">1</span>, <span class="number">4</span>), (<span class="number">1</span>, <span class="number">5</span>)];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().min_set_by(|&&(k1,<span class="kw">_</span>), &&(k2, <span class="kw">_</span>)| k1.cmp(<span class="kw-2">&</span>k2)), <span class="macro">vec!</span>[<span class="kw-2">&</span>(<span class="number">1</span>, <span class="number">2</span>), <span class="kw-2">&</span>(<span class="number">1</span>, <span class="number">3</span>), <span class="kw-2">&</span>(<span class="number">1</span>, <span class="number">4</span>), <span class="kw-2">&</span>(<span class="number">1</span>, <span class="number">5</span>)]);</code></pre></div>
|
|||
|
<p>The elements can be floats but no particular result is guaranteed
|
|||
|
if an element is NaN.</p>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.min_set_by_key" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3256-3263">source</a><h4 class="code-header">fn <a href="#method.min_set_by_key" class="fn">min_set_by_key</a><K, F>(self, key: F) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> K,</div></h4></section></summary><div class="docblock"><p>Return all minimum elements of an iterator, as determined by
|
|||
|
the specified function.</p>
|
|||
|
<h5 id="examples-4"><a href="#examples-4">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>a: [(i32, i32); <span class="number">0</span>] = [];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().min_set_by_key(|<span class="kw">_</span>| ()), Vec::<<span class="kw-2">&</span>(i32, i32)>::new());
|
|||
|
|
|||
|
<span class="kw">let </span>a = [(<span class="number">1</span>, <span class="number">2</span>)];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().min_set_by_key(|&&(k,<span class="kw">_</span>)| k), <span class="macro">vec!</span>[<span class="kw-2">&</span>(<span class="number">1</span>, <span class="number">2</span>)]);
|
|||
|
|
|||
|
<span class="kw">let </span>a = [(<span class="number">1</span>, <span class="number">2</span>), (<span class="number">2</span>, <span class="number">2</span>), (<span class="number">3</span>, <span class="number">9</span>), (<span class="number">4</span>, <span class="number">8</span>), (<span class="number">5</span>, <span class="number">9</span>)];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().min_set_by_key(|&&(<span class="kw">_</span>, k)| k), <span class="macro">vec!</span>[<span class="kw-2">&</span>(<span class="number">1</span>, <span class="number">2</span>), <span class="kw-2">&</span>(<span class="number">2</span>, <span class="number">2</span>)]);
|
|||
|
|
|||
|
<span class="kw">let </span>a = [(<span class="number">1</span>, <span class="number">2</span>), (<span class="number">1</span>, <span class="number">3</span>), (<span class="number">1</span>, <span class="number">4</span>), (<span class="number">1</span>, <span class="number">5</span>)];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().min_set_by_key(|&&(k, <span class="kw">_</span>)| k), <span class="macro">vec!</span>[<span class="kw-2">&</span>(<span class="number">1</span>, <span class="number">2</span>), <span class="kw-2">&</span>(<span class="number">1</span>, <span class="number">3</span>), <span class="kw-2">&</span>(<span class="number">1</span>, <span class="number">4</span>), <span class="kw-2">&</span>(<span class="number">1</span>, <span class="number">5</span>)]);</code></pre></div>
|
|||
|
<p>The elements can be floats but no particular result is guaranteed
|
|||
|
if an element is NaN.</p>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.max_set" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3288-3294">source</a><h4 class="code-header">fn <a href="#method.max_set" class="fn">max_set</a>(self) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>,</div></h4></section></summary><div class="docblock"><p>Return all maximum elements of an iterator.</p>
|
|||
|
<h5 id="examples-5"><a href="#examples-5">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>a: [i32; <span class="number">0</span>] = [];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().max_set(), Vec::<<span class="kw-2">&</span>i32>::new());
|
|||
|
|
|||
|
<span class="kw">let </span>a = [<span class="number">1</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().max_set(), <span class="macro">vec!</span>[<span class="kw-2">&</span><span class="number">1</span>]);
|
|||
|
|
|||
|
<span class="kw">let </span>a = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().max_set(), <span class="macro">vec!</span>[<span class="kw-2">&</span><span class="number">5</span>]);
|
|||
|
|
|||
|
<span class="kw">let </span>a = [<span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().max_set(), <span class="macro">vec!</span>[<span class="kw-2">&</span><span class="number">1</span>, <span class="kw-2">&</span><span class="number">1</span>, <span class="kw-2">&</span><span class="number">1</span>, <span class="kw-2">&</span><span class="number">1</span>]);</code></pre></div>
|
|||
|
<p>The elements can be floats but no particular result is guaranteed
|
|||
|
if an element is NaN.</p>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.max_set_by" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3321-3327">source</a><h4 class="code-header">fn <a href="#method.max_set_by" class="fn">max_set_by</a><F>(self, compare: F) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, &Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a>,</div></h4></section></summary><div class="docblock"><p>Return all maximum elements of an iterator, as determined by
|
|||
|
the specified function.</p>
|
|||
|
<h5 id="examples-6"><a href="#examples-6">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>a: [(i32, i32); <span class="number">0</span>] = [];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().max_set_by(|<span class="kw">_</span>, <span class="kw">_</span>| Ordering::Equal), Vec::<<span class="kw-2">&</span>(i32, i32)>::new());
|
|||
|
|
|||
|
<span class="kw">let </span>a = [(<span class="number">1</span>, <span class="number">2</span>)];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().max_set_by(|&&(k1,<span class="kw">_</span>), &&(k2, <span class="kw">_</span>)| k1.cmp(<span class="kw-2">&</span>k2)), <span class="macro">vec!</span>[<span class="kw-2">&</span>(<span class="number">1</span>, <span class="number">2</span>)]);
|
|||
|
|
|||
|
<span class="kw">let </span>a = [(<span class="number">1</span>, <span class="number">2</span>), (<span class="number">2</span>, <span class="number">2</span>), (<span class="number">3</span>, <span class="number">9</span>), (<span class="number">4</span>, <span class="number">8</span>), (<span class="number">5</span>, <span class="number">9</span>)];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().max_set_by(|&&(<span class="kw">_</span>,k1), &&(<span class="kw">_</span>,k2)| k1.cmp(<span class="kw-2">&</span>k2)), <span class="macro">vec!</span>[<span class="kw-2">&</span>(<span class="number">3</span>, <span class="number">9</span>), <span class="kw-2">&</span>(<span class="number">5</span>, <span class="number">9</span>)]);
|
|||
|
|
|||
|
<span class="kw">let </span>a = [(<span class="number">1</span>, <span class="number">2</span>), (<span class="number">1</span>, <span class="number">3</span>), (<span class="number">1</span>, <span class="number">4</span>), (<span class="number">1</span>, <span class="number">5</span>)];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().max_set_by(|&&(k1,<span class="kw">_</span>), &&(k2, <span class="kw">_</span>)| k1.cmp(<span class="kw-2">&</span>k2)), <span class="macro">vec!</span>[<span class="kw-2">&</span>(<span class="number">1</span>, <span class="number">2</span>), <span class="kw-2">&</span>(<span class="number">1</span>, <span class="number">3</span>), <span class="kw-2">&</span>(<span class="number">1</span>, <span class="number">4</span>), <span class="kw-2">&</span>(<span class="number">1</span>, <span class="number">5</span>)]);</code></pre></div>
|
|||
|
<p>The elements can be floats but no particular result is guaranteed
|
|||
|
if an element is NaN.</p>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.max_set_by_key" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3353-3360">source</a><h4 class="code-header">fn <a href="#method.max_set_by_key" class="fn">max_set_by_key</a><K, F>(self, key: F) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> K,</div></h4></section></summary><div class="docblock"><p>Return all maximum elements of an iterator, as determined by
|
|||
|
the specified function.</p>
|
|||
|
<h5 id="examples-7"><a href="#examples-7">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>a: [(i32, i32); <span class="number">0</span>] = [];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().max_set_by_key(|<span class="kw">_</span>| ()), Vec::<<span class="kw-2">&</span>(i32, i32)>::new());
|
|||
|
|
|||
|
<span class="kw">let </span>a = [(<span class="number">1</span>, <span class="number">2</span>)];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().max_set_by_key(|&&(k,<span class="kw">_</span>)| k), <span class="macro">vec!</span>[<span class="kw-2">&</span>(<span class="number">1</span>, <span class="number">2</span>)]);
|
|||
|
|
|||
|
<span class="kw">let </span>a = [(<span class="number">1</span>, <span class="number">2</span>), (<span class="number">2</span>, <span class="number">2</span>), (<span class="number">3</span>, <span class="number">9</span>), (<span class="number">4</span>, <span class="number">8</span>), (<span class="number">5</span>, <span class="number">9</span>)];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().max_set_by_key(|&&(<span class="kw">_</span>, k)| k), <span class="macro">vec!</span>[<span class="kw-2">&</span>(<span class="number">3</span>, <span class="number">9</span>), <span class="kw-2">&</span>(<span class="number">5</span>, <span class="number">9</span>)]);
|
|||
|
|
|||
|
<span class="kw">let </span>a = [(<span class="number">1</span>, <span class="number">2</span>), (<span class="number">1</span>, <span class="number">3</span>), (<span class="number">1</span>, <span class="number">4</span>), (<span class="number">1</span>, <span class="number">5</span>)];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().max_set_by_key(|&&(k, <span class="kw">_</span>)| k), <span class="macro">vec!</span>[<span class="kw-2">&</span>(<span class="number">1</span>, <span class="number">2</span>), <span class="kw-2">&</span>(<span class="number">1</span>, <span class="number">3</span>), <span class="kw-2">&</span>(<span class="number">1</span>, <span class="number">4</span>), <span class="kw-2">&</span>(<span class="number">1</span>, <span class="number">5</span>)]);</code></pre></div>
|
|||
|
<p>The elements can be floats but no particular result is guaranteed
|
|||
|
if an element is NaN.</p>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.minmax" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3397-3403">source</a><h4 class="code-header">fn <a href="#method.minmax" class="fn">minmax</a>(self) -> <a class="enum" href="enum.MinMaxResult.html" title="enum itertools::MinMaxResult">MinMaxResult</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a>,</div></h4></section></summary><div class="docblock"><p>Return the minimum and maximum elements in the iterator.</p>
|
|||
|
<p>The return type <code>MinMaxResult</code> is an enum of three variants:</p>
|
|||
|
<ul>
|
|||
|
<li><code>NoElements</code> if the iterator is empty.</li>
|
|||
|
<li><code>OneElement(x)</code> if the iterator has exactly one element.</li>
|
|||
|
<li><code>MinMax(x, y)</code> is returned otherwise, where <code>x <= y</code>. Two
|
|||
|
values are equal if and only if there is more than one
|
|||
|
element in the iterator and all elements are equal.</li>
|
|||
|
</ul>
|
|||
|
<p>On an iterator of length <code>n</code>, <code>minmax</code> does <code>1.5 * n</code> comparisons,
|
|||
|
and so is faster than calling <code>min</code> and <code>max</code> separately which does
|
|||
|
<code>2 * n</code> comparisons.</p>
|
|||
|
<h5 id="examples-8"><a href="#examples-8">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
<span class="kw">use </span>itertools::MinMaxResult::{NoElements, OneElement, MinMax};
|
|||
|
|
|||
|
<span class="kw">let </span>a: [i32; <span class="number">0</span>] = [];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().minmax(), NoElements);
|
|||
|
|
|||
|
<span class="kw">let </span>a = [<span class="number">1</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().minmax(), OneElement(<span class="kw-2">&</span><span class="number">1</span>));
|
|||
|
|
|||
|
<span class="kw">let </span>a = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().minmax(), MinMax(<span class="kw-2">&</span><span class="number">1</span>, <span class="kw-2">&</span><span class="number">5</span>));
|
|||
|
|
|||
|
<span class="kw">let </span>a = [<span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().minmax(), MinMax(<span class="kw-2">&</span><span class="number">1</span>, <span class="kw-2">&</span><span class="number">1</span>));</code></pre></div>
|
|||
|
<p>The elements can be floats but no particular result is guaranteed
|
|||
|
if an element is NaN.</p>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.minmax_by_key" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3416-3423">source</a><h4 class="code-header">fn <a href="#method.minmax_by_key" class="fn">minmax_by_key</a><K, F>(self, key: F) -> <a class="enum" href="enum.MinMaxResult.html" title="enum itertools::MinMaxResult">MinMaxResult</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> K,</div></h4></section></summary><div class="docblock"><p>Return the minimum and maximum element of an iterator, as determined by
|
|||
|
the specified function.</p>
|
|||
|
<p>The return value is a variant of <a href="enum.MinMaxResult.html" title="enum itertools::MinMaxResult"><code>MinMaxResult</code></a> like for <a href="trait.Itertools.html#method.minmax" title="method itertools::Itertools::minmax"><code>.minmax()</code></a>.</p>
|
|||
|
<p>For the minimum, the first minimal element is returned. For the maximum,
|
|||
|
the last maximal element wins. This matches the behavior of the standard
|
|||
|
<a href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#method.min" title="method core::iter::traits::iterator::Iterator::min"><code>Iterator::min</code></a> and <a href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#method.max" title="method core::iter::traits::iterator::Iterator::max"><code>Iterator::max</code></a> methods.</p>
|
|||
|
<p>The keys can be floats but no particular result is guaranteed
|
|||
|
if a key is NaN.</p>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.minmax_by" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3433-3439">source</a><h4 class="code-header">fn <a href="#method.minmax_by" class="fn">minmax_by</a><F>(self, compare: F) -> <a class="enum" href="enum.MinMaxResult.html" title="enum itertools::MinMaxResult">MinMaxResult</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, &Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a>,</div></h4></section></summary><div class="docblock"><p>Return the minimum and maximum element of an iterator, as determined by
|
|||
|
the specified comparison function.</p>
|
|||
|
<p>The return value is a variant of <a href="enum.MinMaxResult.html" title="enum itertools::MinMaxResult"><code>MinMaxResult</code></a> like for <a href="trait.Itertools.html#method.minmax" title="method itertools::Itertools::minmax"><code>.minmax()</code></a>.</p>
|
|||
|
<p>For the minimum, the first minimal element is returned. For the maximum,
|
|||
|
the last maximal element wins. This matches the behavior of the standard
|
|||
|
<a href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#method.min" title="method core::iter::traits::iterator::Iterator::min"><code>Iterator::min</code></a> and <a href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#method.max" title="method core::iter::traits::iterator::Iterator::max"><code>Iterator::max</code></a> methods.</p>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.position_max" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3460-3468">source</a><h4 class="code-header">fn <a href="#method.position_max" class="fn">position_max</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>,</div></h4></section></summary><div class="docblock"><p>Return the position of the maximum element in the iterator.</p>
|
|||
|
<p>If several elements are equally maximum, the position of the
|
|||
|
last of them is returned.</p>
|
|||
|
<h5 id="examples-9"><a href="#examples-9">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>a: [i32; <span class="number">0</span>] = [];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_max(), <span class="prelude-val">None</span>);
|
|||
|
|
|||
|
<span class="kw">let </span>a = [-<span class="number">3</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">5</span>, -<span class="number">10</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_max(), <span class="prelude-val">Some</span>(<span class="number">3</span>));
|
|||
|
|
|||
|
<span class="kw">let </span>a = [<span class="number">1</span>, <span class="number">1</span>, -<span class="number">1</span>, -<span class="number">1</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_max(), <span class="prelude-val">Some</span>(<span class="number">1</span>));</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.position_max_by_key" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3490-3499">source</a><h4 class="code-header">fn <a href="#method.position_max_by_key" class="fn">position_max_by_key</a><K, F>(self, key: F) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> K,</div></h4></section></summary><div class="docblock"><p>Return the position of the maximum element in the iterator, as
|
|||
|
determined by the specified function.</p>
|
|||
|
<p>If several elements are equally maximum, the position of the
|
|||
|
last of them is returned.</p>
|
|||
|
<h5 id="examples-10"><a href="#examples-10">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>a: [i32; <span class="number">0</span>] = [];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_max_by_key(|x| x.abs()), <span class="prelude-val">None</span>);
|
|||
|
|
|||
|
<span class="kw">let </span>a = [-<span class="number">3_i32</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">5</span>, -<span class="number">10</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_max_by_key(|x| x.abs()), <span class="prelude-val">Some</span>(<span class="number">4</span>));
|
|||
|
|
|||
|
<span class="kw">let </span>a = [<span class="number">1_i32</span>, <span class="number">1</span>, -<span class="number">1</span>, -<span class="number">1</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_max_by_key(|x| x.abs()), <span class="prelude-val">Some</span>(<span class="number">3</span>));</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.position_max_by" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3521-3529">source</a><h4 class="code-header">fn <a href="#method.position_max_by" class="fn">position_max_by</a><F>(self, compare: F) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, &Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a>,</div></h4></section></summary><div class="docblock"><p>Return the position of the maximum element in the iterator, as
|
|||
|
determined by the specified comparison function.</p>
|
|||
|
<p>If several elements are equally maximum, the position of the
|
|||
|
last of them is returned.</p>
|
|||
|
<h5 id="examples-11"><a href="#examples-11">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>a: [i32; <span class="number">0</span>] = [];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_max_by(|x, y| x.cmp(y)), <span class="prelude-val">None</span>);
|
|||
|
|
|||
|
<span class="kw">let </span>a = [-<span class="number">3_i32</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">5</span>, -<span class="number">10</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_max_by(|x, y| x.cmp(y)), <span class="prelude-val">Some</span>(<span class="number">3</span>));
|
|||
|
|
|||
|
<span class="kw">let </span>a = [<span class="number">1_i32</span>, <span class="number">1</span>, -<span class="number">1</span>, -<span class="number">1</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_max_by(|x, y| x.cmp(y)), <span class="prelude-val">Some</span>(<span class="number">1</span>));</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.position_min" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3550-3558">source</a><h4 class="code-header">fn <a href="#method.position_min" class="fn">position_min</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>,</div></h4></section></summary><div class="docblock"><p>Return the position of the minimum element in the iterator.</p>
|
|||
|
<p>If several elements are equally minimum, the position of the
|
|||
|
first of them is returned.</p>
|
|||
|
<h5 id="examples-12"><a href="#examples-12">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>a: [i32; <span class="number">0</span>] = [];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_min(), <span class="prelude-val">None</span>);
|
|||
|
|
|||
|
<span class="kw">let </span>a = [-<span class="number">3</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">5</span>, -<span class="number">10</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_min(), <span class="prelude-val">Some</span>(<span class="number">4</span>));
|
|||
|
|
|||
|
<span class="kw">let </span>a = [<span class="number">1</span>, <span class="number">1</span>, -<span class="number">1</span>, -<span class="number">1</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_min(), <span class="prelude-val">Some</span>(<span class="number">2</span>));</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.position_min_by_key" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3580-3589">source</a><h4 class="code-header">fn <a href="#method.position_min_by_key" class="fn">position_min_by_key</a><K, F>(self, key: F) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> K,</div></h4></section></summary><div class="docblock"><p>Return the position of the minimum element in the iterator, as
|
|||
|
determined by the specified function.</p>
|
|||
|
<p>If several elements are equally minimum, the position of the
|
|||
|
first of them is returned.</p>
|
|||
|
<h5 id="examples-13"><a href="#examples-13">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>a: [i32; <span class="number">0</span>] = [];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_min_by_key(|x| x.abs()), <span class="prelude-val">None</span>);
|
|||
|
|
|||
|
<span class="kw">let </span>a = [-<span class="number">3_i32</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">5</span>, -<span class="number">10</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_min_by_key(|x| x.abs()), <span class="prelude-val">Some</span>(<span class="number">1</span>));
|
|||
|
|
|||
|
<span class="kw">let </span>a = [<span class="number">1_i32</span>, <span class="number">1</span>, -<span class="number">1</span>, -<span class="number">1</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_min_by_key(|x| x.abs()), <span class="prelude-val">Some</span>(<span class="number">0</span>));</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.position_min_by" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3611-3619">source</a><h4 class="code-header">fn <a href="#method.position_min_by" class="fn">position_min_by</a><F>(self, compare: F) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, &Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a>,</div></h4></section></summary><div class="docblock"><p>Return the position of the minimum element in the iterator, as
|
|||
|
determined by the specified comparison function.</p>
|
|||
|
<p>If several elements are equally minimum, the position of the
|
|||
|
first of them is returned.</p>
|
|||
|
<h5 id="examples-14"><a href="#examples-14">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>a: [i32; <span class="number">0</span>] = [];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_min_by(|x, y| x.cmp(y)), <span class="prelude-val">None</span>);
|
|||
|
|
|||
|
<span class="kw">let </span>a = [-<span class="number">3_i32</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">5</span>, -<span class="number">10</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_min_by(|x, y| x.cmp(y)), <span class="prelude-val">Some</span>(<span class="number">4</span>));
|
|||
|
|
|||
|
<span class="kw">let </span>a = [<span class="number">1_i32</span>, <span class="number">1</span>, -<span class="number">1</span>, -<span class="number">1</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_min_by(|x, y| x.cmp(y)), <span class="prelude-val">Some</span>(<span class="number">2</span>));</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.position_minmax" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3663-3674">source</a><h4 class="code-header">fn <a href="#method.position_minmax" class="fn">position_minmax</a>(self) -> <a class="enum" href="enum.MinMaxResult.html" title="enum itertools::MinMaxResult">MinMaxResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a>,</div></h4></section></summary><div class="docblock"><p>Return the positions of the minimum and maximum elements in
|
|||
|
the iterator.</p>
|
|||
|
<p>The return type <a href="enum.MinMaxResult.html" title="enum itertools::MinMaxResult"><code>MinMaxResult</code></a> is an enum of three variants:</p>
|
|||
|
<ul>
|
|||
|
<li><code>NoElements</code> if the iterator is empty.</li>
|
|||
|
<li><code>OneElement(xpos)</code> if the iterator has exactly one element.</li>
|
|||
|
<li><code>MinMax(xpos, ypos)</code> is returned otherwise, where the
|
|||
|
element at <code>xpos</code> ≤ the element at <code>ypos</code>. While the
|
|||
|
referenced elements themselves may be equal, <code>xpos</code> cannot
|
|||
|
be equal to <code>ypos</code>.</li>
|
|||
|
</ul>
|
|||
|
<p>On an iterator of length <code>n</code>, <code>position_minmax</code> does <code>1.5 * n</code>
|
|||
|
comparisons, and so is faster than calling <code>position_min</code> and
|
|||
|
<code>position_max</code> separately which does <code>2 * n</code> comparisons.</p>
|
|||
|
<p>For the minimum, if several elements are equally minimum, the
|
|||
|
position of the first of them is returned. For the maximum, if
|
|||
|
several elements are equally maximum, the position of the last
|
|||
|
of them is returned.</p>
|
|||
|
<p>The elements can be floats but no particular result is
|
|||
|
guaranteed if an element is NaN.</p>
|
|||
|
<h5 id="examples-15"><a href="#examples-15">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
<span class="kw">use </span>itertools::MinMaxResult::{NoElements, OneElement, MinMax};
|
|||
|
|
|||
|
<span class="kw">let </span>a: [i32; <span class="number">0</span>] = [];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_minmax(), NoElements);
|
|||
|
|
|||
|
<span class="kw">let </span>a = [<span class="number">10</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_minmax(), OneElement(<span class="number">0</span>));
|
|||
|
|
|||
|
<span class="kw">let </span>a = [-<span class="number">3</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">5</span>, -<span class="number">10</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_minmax(), MinMax(<span class="number">4</span>, <span class="number">3</span>));
|
|||
|
|
|||
|
<span class="kw">let </span>a = [<span class="number">1</span>, <span class="number">1</span>, -<span class="number">1</span>, -<span class="number">1</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_minmax(), MinMax(<span class="number">2</span>, <span class="number">1</span>));</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.position_minmax_by_key" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3710-3722">source</a><h4 class="code-header">fn <a href="#method.position_minmax_by_key" class="fn">position_minmax_by_key</a><K, F>(self, key: F) -> <a class="enum" href="enum.MinMaxResult.html" title="enum itertools::MinMaxResult">MinMaxResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> K,</div></h4></section></summary><div class="docblock"><p>Return the postions of the minimum and maximum elements of an
|
|||
|
iterator, as determined by the specified function.</p>
|
|||
|
<p>The return value is a variant of <a href="enum.MinMaxResult.html" title="enum itertools::MinMaxResult"><code>MinMaxResult</code></a> like for
|
|||
|
<a href="trait.Itertools.html#method.position_minmax"><code>position_minmax</code></a>.</p>
|
|||
|
<p>For the minimum, if several elements are equally minimum, the
|
|||
|
position of the first of them is returned. For the maximum, if
|
|||
|
several elements are equally maximum, the position of the last
|
|||
|
of them is returned.</p>
|
|||
|
<p>The keys can be floats but no particular result is guaranteed
|
|||
|
if a key is NaN.</p>
|
|||
|
<h5 id="examples-16"><a href="#examples-16">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
<span class="kw">use </span>itertools::MinMaxResult::{NoElements, OneElement, MinMax};
|
|||
|
|
|||
|
<span class="kw">let </span>a: [i32; <span class="number">0</span>] = [];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_minmax_by_key(|x| x.abs()), NoElements);
|
|||
|
|
|||
|
<span class="kw">let </span>a = [<span class="number">10_i32</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_minmax_by_key(|x| x.abs()), OneElement(<span class="number">0</span>));
|
|||
|
|
|||
|
<span class="kw">let </span>a = [-<span class="number">3_i32</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">5</span>, -<span class="number">10</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_minmax_by_key(|x| x.abs()), MinMax(<span class="number">1</span>, <span class="number">4</span>));
|
|||
|
|
|||
|
<span class="kw">let </span>a = [<span class="number">1_i32</span>, <span class="number">1</span>, -<span class="number">1</span>, -<span class="number">1</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_minmax_by_key(|x| x.abs()), MinMax(<span class="number">0</span>, <span class="number">3</span>));</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.position_minmax_by" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3755-3766">source</a><h4 class="code-header">fn <a href="#method.position_minmax_by" class="fn">position_minmax_by</a><F>(self, compare: F) -> <a class="enum" href="enum.MinMaxResult.html" title="enum itertools::MinMaxResult">MinMaxResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, &Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a>,</div></h4></section></summary><div class="docblock"><p>Return the postions of the minimum and maximum elements of an
|
|||
|
iterator, as determined by the specified comparison function.</p>
|
|||
|
<p>The return value is a variant of <a href="enum.MinMaxResult.html" title="enum itertools::MinMaxResult"><code>MinMaxResult</code></a> like for
|
|||
|
<a href="trait.Itertools.html#method.position_minmax"><code>position_minmax</code></a>.</p>
|
|||
|
<p>For the minimum, if several elements are equally minimum, the
|
|||
|
position of the first of them is returned. For the maximum, if
|
|||
|
several elements are equally maximum, the position of the last
|
|||
|
of them is returned.</p>
|
|||
|
<h5 id="examples-17"><a href="#examples-17">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
<span class="kw">use </span>itertools::MinMaxResult::{NoElements, OneElement, MinMax};
|
|||
|
|
|||
|
<span class="kw">let </span>a: [i32; <span class="number">0</span>] = [];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_minmax_by(|x, y| x.cmp(y)), NoElements);
|
|||
|
|
|||
|
<span class="kw">let </span>a = [<span class="number">10_i32</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_minmax_by(|x, y| x.cmp(y)), OneElement(<span class="number">0</span>));
|
|||
|
|
|||
|
<span class="kw">let </span>a = [-<span class="number">3_i32</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">5</span>, -<span class="number">10</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_minmax_by(|x, y| x.cmp(y)), MinMax(<span class="number">4</span>, <span class="number">3</span>));
|
|||
|
|
|||
|
<span class="kw">let </span>a = [<span class="number">1_i32</span>, <span class="number">1</span>, -<span class="number">1</span>, -<span class="number">1</span>];
|
|||
|
<span class="macro">assert_eq!</span>(a.iter().position_minmax_by(|x, y| x.cmp(y)), MinMax(<span class="number">2</span>, <span class="number">1</span>));</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.exactly_one" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3785-3799">source</a><h4 class="code-header">fn <a href="#method.exactly_one" class="fn">exactly_one</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, <a class="struct" href="structs/struct.ExactlyOneError.html" title="struct itertools::structs::ExactlyOneError">ExactlyOneError</a><Self>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>If the iterator yields exactly one element, that element will be returned, otherwise
|
|||
|
an error will be returned containing an iterator that has the same output as the input
|
|||
|
iterator.</p>
|
|||
|
<p>This provides an additional layer of validation over just calling <code>Iterator::next()</code>.
|
|||
|
If your assumption that there should only be one element yielded is false this provides
|
|||
|
the opportunity to detect and handle that, preventing errors at a distance.</p>
|
|||
|
<h5 id="examples-18"><a href="#examples-18">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>((<span class="number">0</span>..<span class="number">10</span>).filter(|<span class="kw-2">&</span>x| x == <span class="number">2</span>).exactly_one().unwrap(), <span class="number">2</span>);
|
|||
|
<span class="macro">assert!</span>((<span class="number">0</span>..<span class="number">10</span>).filter(|<span class="kw-2">&</span>x| x > <span class="number">1 </span>&& x < <span class="number">4</span>).exactly_one().unwrap_err().eq(<span class="number">2</span>..<span class="number">4</span>));
|
|||
|
<span class="macro">assert!</span>((<span class="number">0</span>..<span class="number">10</span>).filter(|<span class="kw-2">&</span>x| x > <span class="number">1 </span>&& x < <span class="number">5</span>).exactly_one().unwrap_err().eq(<span class="number">2</span>..<span class="number">5</span>));
|
|||
|
<span class="macro">assert!</span>((<span class="number">0</span>..<span class="number">10</span>).filter(|<span class="kw-2">&</span><span class="kw">_</span>| <span class="bool-val">false</span>).exactly_one().unwrap_err().eq(<span class="number">0</span>..<span class="number">0</span>));</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.at_most_one" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3818-3832">source</a><h4 class="code-header">fn <a href="#method.at_most_one" class="fn">at_most_one</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>>, <a class="struct" href="structs/struct.ExactlyOneError.html" title="struct itertools::structs::ExactlyOneError">ExactlyOneError</a><Self>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>If the iterator yields no elements, Ok(None) will be returned. If the iterator yields
|
|||
|
exactly one element, that element will be returned, otherwise an error will be returned
|
|||
|
containing an iterator that has the same output as the input iterator.</p>
|
|||
|
<p>This provides an additional layer of validation over just calling <code>Iterator::next()</code>.
|
|||
|
If your assumption that there should be at most one element yielded is false this provides
|
|||
|
the opportunity to detect and handle that, preventing errors at a distance.</p>
|
|||
|
<h5 id="examples-19"><a href="#examples-19">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>((<span class="number">0</span>..<span class="number">10</span>).filter(|<span class="kw-2">&</span>x| x == <span class="number">2</span>).at_most_one().unwrap(), <span class="prelude-val">Some</span>(<span class="number">2</span>));
|
|||
|
<span class="macro">assert!</span>((<span class="number">0</span>..<span class="number">10</span>).filter(|<span class="kw-2">&</span>x| x > <span class="number">1 </span>&& x < <span class="number">4</span>).at_most_one().unwrap_err().eq(<span class="number">2</span>..<span class="number">4</span>));
|
|||
|
<span class="macro">assert!</span>((<span class="number">0</span>..<span class="number">10</span>).filter(|<span class="kw-2">&</span>x| x > <span class="number">1 </span>&& x < <span class="number">5</span>).at_most_one().unwrap_err().eq(<span class="number">2</span>..<span class="number">5</span>));
|
|||
|
<span class="macro">assert_eq!</span>((<span class="number">0</span>..<span class="number">10</span>).filter(|<span class="kw-2">&</span><span class="kw">_</span>| <span class="bool-val">false</span>).at_most_one().unwrap(), <span class="prelude-val">None</span>);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.multipeek" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3849-3854">source</a><h4 class="code-header">fn <a href="#method.multipeek" class="fn">multipeek</a>(self) -> <a class="struct" href="structs/struct.MultiPeek.html" title="struct itertools::structs::MultiPeek">MultiPeek</a><Self> <a href="#" class="tooltip" data-notable-ty="MultiPeek<Self>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>An iterator adaptor that allows the user to peek at multiple <code>.next()</code>
|
|||
|
values without advancing the base iterator.</p>
|
|||
|
<h5 id="examples-20"><a href="#examples-20">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span><span class="kw-2">mut </span>iter = (<span class="number">0</span>..<span class="number">10</span>).multipeek();
|
|||
|
<span class="macro">assert_eq!</span>(iter.peek(), <span class="prelude-val">Some</span>(<span class="kw-2">&</span><span class="number">0</span>));
|
|||
|
<span class="macro">assert_eq!</span>(iter.peek(), <span class="prelude-val">Some</span>(<span class="kw-2">&</span><span class="number">1</span>));
|
|||
|
<span class="macro">assert_eq!</span>(iter.peek(), <span class="prelude-val">Some</span>(<span class="kw-2">&</span><span class="number">2</span>));
|
|||
|
<span class="macro">assert_eq!</span>(iter.next(), <span class="prelude-val">Some</span>(<span class="number">0</span>));
|
|||
|
<span class="macro">assert_eq!</span>(iter.peek(), <span class="prelude-val">Some</span>(<span class="kw-2">&</span><span class="number">1</span>));</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.counts" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3870-3878">source</a><h4 class="code-header">fn <a href="#method.counts" class="fn">counts</a>(self) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/collections/hash/map/struct.HashMap.html" title="struct std::collections::hash::map::HashMap">HashMap</a><Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>, <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a>,</div></h4></section></summary><div class="docblock"><p>Collect the items in this iterator and return a <code>HashMap</code> which
|
|||
|
contains each item that appears in the iterator and the number
|
|||
|
of times it appears.</p>
|
|||
|
<h5 id="examples-21"><a href="#examples-21">Examples</a></h5>
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>counts = [<span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">3</span>, <span class="number">3</span>, <span class="number">5</span>].into_iter().counts();
|
|||
|
<span class="macro">assert_eq!</span>(counts[<span class="kw-2">&</span><span class="number">1</span>], <span class="number">3</span>);
|
|||
|
<span class="macro">assert_eq!</span>(counts[<span class="kw-2">&</span><span class="number">3</span>], <span class="number">2</span>);
|
|||
|
<span class="macro">assert_eq!</span>(counts[<span class="kw-2">&</span><span class="number">5</span>], <span class="number">1</span>);
|
|||
|
<span class="macro">assert_eq!</span>(counts.get(<span class="kw-2">&</span><span class="number">0</span>), <span class="prelude-val">None</span>);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.counts_by" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3913-3920">source</a><h4 class="code-header">fn <a href="#method.counts_by" class="fn">counts_by</a><K, F>(self, f: F) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/collections/hash/map/struct.HashMap.html" title="struct std::collections::hash::map::HashMap">HashMap</a><K, <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
K: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>) -> K,</div></h4></section></summary><div class="docblock"><p>Collect the items in this iterator and return a <code>HashMap</code> which
|
|||
|
contains each item that appears in the iterator and the number
|
|||
|
of times it appears,
|
|||
|
determining identity using a keying function.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">struct </span>Character {
|
|||
|
first_name: <span class="kw-2">&</span><span class="lifetime">'static </span>str,
|
|||
|
last_name: <span class="kw-2">&</span><span class="lifetime">'static </span>str,
|
|||
|
}
|
|||
|
|
|||
|
<span class="kw">let </span>characters =
|
|||
|
<span class="macro">vec!</span>[
|
|||
|
Character { first_name: <span class="string">"Amy"</span>, last_name: <span class="string">"Pond" </span>},
|
|||
|
Character { first_name: <span class="string">"Amy"</span>, last_name: <span class="string">"Wong" </span>},
|
|||
|
Character { first_name: <span class="string">"Amy"</span>, last_name: <span class="string">"Santiago" </span>},
|
|||
|
Character { first_name: <span class="string">"James"</span>, last_name: <span class="string">"Bond" </span>},
|
|||
|
Character { first_name: <span class="string">"James"</span>, last_name: <span class="string">"Sullivan" </span>},
|
|||
|
Character { first_name: <span class="string">"James"</span>, last_name: <span class="string">"Norington" </span>},
|
|||
|
Character { first_name: <span class="string">"James"</span>, last_name: <span class="string">"Kirk" </span>},
|
|||
|
];
|
|||
|
|
|||
|
<span class="kw">let </span>first_name_frequency =
|
|||
|
characters
|
|||
|
.into_iter()
|
|||
|
.counts_by(|c| c.first_name);
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(first_name_frequency[<span class="string">"Amy"</span>], <span class="number">3</span>);
|
|||
|
<span class="macro">assert_eq!</span>(first_name_frequency[<span class="string">"James"</span>], <span class="number">4</span>);
|
|||
|
<span class="macro">assert_eq!</span>(first_name_frequency.contains_key(<span class="string">"Asha"</span>), <span class="bool-val">false</span>);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.multiunzip" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3942-3947">source</a><h4 class="code-header">fn <a href="#method.multiunzip" class="fn">multiunzip</a><FromI>(self) -> FromI<div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="trait.MultiUnzip.html" title="trait itertools::MultiUnzip">MultiUnzip</a><FromI>,</div></h4></section></summary><div class="docblock"><p>Converts an iterator of tuples into a tuple of containers.</p>
|
|||
|
<p><code>unzip()</code> consumes an entire iterator of n-ary tuples, producing <code>n</code> collections, one for each
|
|||
|
column.</p>
|
|||
|
<p>This function is, in some sense, the opposite of <a href="fn.multizip.html" title="fn itertools::multizip"><code>multizip</code></a>.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="kw">let </span>inputs = <span class="macro">vec!</span>[(<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>), (<span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>), (<span class="number">7</span>, <span class="number">8</span>, <span class="number">9</span>)];
|
|||
|
|
|||
|
<span class="kw">let </span>(a, b, c): (Vec<<span class="kw">_</span>>, Vec<<span class="kw">_</span>>, Vec<<span class="kw">_</span>>) = inputs
|
|||
|
.into_iter()
|
|||
|
.multiunzip();
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>(a, <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">4</span>, <span class="number">7</span>]);
|
|||
|
<span class="macro">assert_eq!</span>(b, <span class="macro">vec!</span>[<span class="number">2</span>, <span class="number">5</span>, <span class="number">8</span>]);
|
|||
|
<span class="macro">assert_eq!</span>(c, <span class="macro">vec!</span>[<span class="number">3</span>, <span class="number">6</span>, <span class="number">9</span>]);</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.try_len" class="method"><a class="src rightside" href="../src/itertools/lib.rs.html#3965-3971">source</a><h4 class="code-header">fn <a href="#method.try_len" class="fn">try_len</a>(&self) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>, (<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>, <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>>)></h4></section></summary><div class="docblock"><p>Returns the length of the iterator if one exists.
|
|||
|
Otherwise return <code>self.size_hint()</code>.</p>
|
|||
|
<p>Fallible <a href="https://doc.rust-lang.org/1.76.0/core/iter/traits/exact_size/trait.ExactSizeIterator.html#method.len" title="method core::iter::traits::exact_size::ExactSizeIterator::len"><code>ExactSizeIterator::len</code></a>.</p>
|
|||
|
<p>Inherits guarantees and restrictions from <a href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#method.size_hint" title="method core::iter::traits::iterator::Iterator::size_hint"><code>Iterator::size_hint</code></a>.</p>
|
|||
|
|
|||
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>itertools::Itertools;
|
|||
|
|
|||
|
<span class="macro">assert_eq!</span>([<span class="number">0</span>; <span class="number">10</span>].iter().try_len(), <span class="prelude-val">Ok</span>(<span class="number">10</span>));
|
|||
|
<span class="macro">assert_eq!</span>((<span class="number">10</span>..<span class="number">15</span>).try_len(), <span class="prelude-val">Ok</span>(<span class="number">5</span>));
|
|||
|
<span class="macro">assert_eq!</span>((<span class="number">15</span>..<span class="number">10</span>).try_len(), <span class="prelude-val">Ok</span>(<span class="number">0</span>));
|
|||
|
<span class="macro">assert_eq!</span>((<span class="number">10</span>..).try_len(), <span class="prelude-val">Err</span>((usize::MAX, <span class="prelude-val">None</span>)));
|
|||
|
<span class="macro">assert_eq!</span>((<span class="number">10</span>..<span class="number">15</span>).filter(|x| x % <span class="number">2 </span>== <span class="number">0</span>).try_len(), <span class="prelude-val">Err</span>((<span class="number">0</span>, <span class="prelude-val">Some</span>(<span class="number">5</span>))));</code></pre></div>
|
|||
|
</div></details></div><h2 id="object-safety" class="section-header">Object Safety<a href="#object-safety" class="anchor">§</a></h2><div class="object-safety-info">This trait is <b>not</b> <a href="https://doc.rust-lang.org/1.76.0/reference/items/traits.html#object-safety">object safe</a>.</div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-Itertools-for-T" class="impl"><a class="src rightside" href="../src/itertools/lib.rs.html#3974">source</a><a href="#impl-Itertools-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="trait.Itertools.html" title="trait itertools::Itertools">Itertools</a> for T<div class="where">where
|
|||
|
T: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></div><script src="../trait.impl/itertools/trait.Itertools.js" async></script><script type="text/json" id="notable-traits-data">{"Batching<Self, F>":"<h3>Notable traits for <code><a class=\"struct\" href=\"structs/struct.Batching.html\" title=\"struct itertools::structs::Batching\">Batching</a><I, F></code></h3><pre><code><div class=\"where\">impl<B, F, I> <a class=\"trait\" href=\"https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html\" title=\"trait core::iter::traits::iterator::Iterator\">Iterator</a> for <a class=\"struct\" href=\"structs/struct.Batching.html\" title=\"struct itertools::structs::Batching\">Batching</a><I, F><div class=\"where\">where\n I: <a class=\"trait\" href=\"https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html\" title=\"trait core::iter::traits::iterator::Iterator\">Iterator</a>,\n F: <a class=\"trait\" href=\"https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html\" title=\"trait core::ops::function::FnMut\">FnMut</a>(<a class=\"primitive\" href=\"https://doc.rust-lang.org/1.76.0/std/primitive.reference.html\">&mut I</a>) -> <a class=\"enum\" href=\"https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html\" title=\"enum core::option::Option\">Option</a><B>,</div></div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item\" class=\"associatedtype\">Item</a> = B;</div>","CircularTupleWindows<Self, T>":"<h3>Notable traits for <code><a class=\"struct\" href=\"structs/struct.CircularTupleWindows.html\" title=\"struct itertools::structs::CircularTupleWindows\">CircularTupleWindows</a><I, T></code></h3><pre><code><div class=\"where\">impl<I, T> <a class=\"trait\" href=\"https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html\" title=\"trait core::iter::traits::iterator::Iterator\">Iterator</a> for <a class=\"struct\" href=\"structs/struct.CircularTupleWindows.html\" title=\"struct itertools::structs::CircularTupleWindows\">CircularTupleWindows</a><I, T><div class=\"where\">where\n I: <a class=\"trait\" href=\"https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html\" title=\"trait core::iter::traits::iterator::Iterator\">Iterator</a><Item = T::Item> + <a class=\"trait\" href=\"https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html\" title=\"trait core::clone::Clone\">Clone</a>,\n T: TupleCollect + <a class=\"trait\" href=\"https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html\" title=\"trait core::clone::Clone\">Clone</a>,\n T::Item: <a class=\"trait\" href=\"https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html\" title=\"trait core::clone::Clone\">Clone</a>,</div></div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item\" class=\"associatedtype\">Item</a> = T;</div>","Combinations<Self>":"<h3>Notable traits for <code><a class=\"struct\" href=\"structs/struct.Combinations.html\" title=\"struct itertools::structs::Combinations\">Combinations</a><I></code></h3><pre><code><div class=\"where\">impl<I> <a class=\"trait\" href=\"https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html\" title=\"trait core::iter::traits::iterator::Iterator\">Iterator</a> for <a class=\"struct\" href=\"structs/struct.Combinations.html\" title=\"struct itertools::structs::Combinations\">Combinations</a><I><div class=\"where\">where\n I: <a class=\"trait\" href=\"https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html\" title=\"trait core::iter::traits::iterator::Iterato
|