Questions tagged [rust-itertools]

For questions about the `itertools` Rust crate, a library for working with iterators. Add [rust] alongside it. For the Python module, see [python-itertools] instead.

Itertools is a library containing useful constructs for working with iterators. Its main attraction is the Itertools extension trait, which adds more adaptors to iterator types.

When using this tag, do not forget to add the tag as well. Only use if your question pertains specifically to the use of the itertools crate, rather than including it in all Rust questions with code depending on it.


The Python module lives in a different tag: .

22 questions
0
votes
1 answer

Is there an iterator method that takes a predicate and gives back an index and the matching element?

I am searching for something like this: let iter = vec![1, 2, 40, 3].into_iter(); let (pos, elt) = iter.position_find(|&x| x > 10); // ^ does not exist println!("{pos} {elt}"); // 2 40 Both Iterator::position and Iterator::find…
leo848
  • 637
  • 2
  • 7
  • 24
0
votes
2 answers

Rust itertools combinations with variable length counts

I want to calculate a vector's combination. I am able to do it easily using itertools::Itertools:combinations trait like this: vec![1, 2, 3].iter().combinations(2).for_each(|x| { println!("{:?}", x); }); But I want to specify the combination…
bayramkazik
  • 27
  • 1
  • 9
0
votes
1 answer

Combining Two Vectors of References into a Vector of Values Without Consuming an Iterator in Rust

I'm currently working with Rust and I'm trying to combine two vectors of references into a single vector of values, without consuming an iterator. Here's the situation: I'm generating vectors by iterating over specific combinations (2 elements from…
Azriel 1rf
  • 147
  • 11
0
votes
0 answers

How to write a trait function which can be invoked on vec and returns an iterable?

I wrote something which I've been using to combine itertools sort+group. pub trait SortAndGroup: Iterator { fn sort_and_group(self, key_selector: fn(&Self::Item) -> K) -> Vec<(K, Vec)> where Self: Sized, K:…
ditoslav
  • 4,563
  • 10
  • 47
  • 79
0
votes
1 answer

Rust vector type conversion / interface issue between Itertools and function with slice indexing

Aim: generate permutations and index into each one in parallel. Attempt: use Itertools to assign all permutations to a resulting vector and then use rayon to process each one. Minimum reproducible code: use rayon::iter::ParallelIterator; use…
Isambard_FA
  • 97
  • 13
0
votes
0 answers

How can I use Itertools::group_by without cloning or the error "cannot move out of a value which is behind a shared reference"?

I have what seems to me like a simple Itertools::group_by task, but I can't make it compile unless I add clone calls. use itertools::Itertools; // 0.9.0; use std::collections::HashMap; #[derive(Debug, Clone, PartialEq, Eq)] pub struct Server { …
Emmanuel Touzery
  • 9,008
  • 3
  • 65
  • 81
0
votes
0 answers

What is the fully-qualified type name of the value returned by put_back?

I am trying to create a struct that will hold an iterator returned by itertools::put_back. I do not know the type name to use for the struct member. Here is how I obtain the iterator over a String: use itertools::put_back; // 0.8.0 fn main() { …
Paul Chernoch
  • 5,275
  • 3
  • 52
  • 73
1
2