#iterator #chunks #windows

no-std itermore

🤸‍♀️ More iterator adaptors

9 releases (breaking)

0.7.1 Dec 15, 2023
0.7.0 Dec 15, 2023
0.6.0 Nov 28, 2023
0.5.0 Dec 4, 2022
0.1.0 Oct 6, 2021

#149 in Algorithms

Download history 554/week @ 2024-08-14 127/week @ 2024-08-21 175/week @ 2024-08-28 105/week @ 2024-09-04 66/week @ 2024-09-11 360/week @ 2024-09-18 144/week @ 2024-09-25 128/week @ 2024-10-02 121/week @ 2024-10-09 150/week @ 2024-10-16 195/week @ 2024-10-23 731/week @ 2024-10-30 305/week @ 2024-11-06 411/week @ 2024-11-13 214/week @ 2024-11-20 498/week @ 2024-11-27

1,540 downloads per month
Used in 4 crates

MIT/Apache

67KB
1K SLoC

itermore

Crates.io Version Docs.rs Latest Build Status

🤸‍♀️ More iterator adaptors.

This crate provides some useful iterator adaptors and functions. Unlike itertools this crate provides a separate extension trait for each adaptor. Additionally, each type of adaptor is feature flagged so you only have to compile the features you need.

Getting started

Add the crate to Cargo manifest.

cargo add itermore --features full

And bring the extension traits into scope.

use itermore::prelude::*;

Now you can use extension methods like array_windows on any iterator.

for [a, b, c] in iter.array_windows() {
    println!("{} {} {}", a, b, c)
}
// Outputs
//    1 2 3
//    2 3 4
//    3 4 5

It is recommended to only enable the features that you need. For example if you only want the array_combinations adaptor you would add the following to your Cargo manifest.

[dependencies]
itermore = { version = "*", features = ["array_combinations"]}

Provided functionality

Methods

  • collect_array: Collects an iterator into an array.
  • min_max and friends: Returns the minimum and maximum element of an iterator.
  • next_chunk: Returns the next N elements of the iterator as an array.
  • sorted and friends: Returns a new iterator with all elements sorted.

Adaptors

  • array_chunks returns an iterator over N elements of the iterator at a time.
  • array_windows returns an iterator over all contiguous windows of length N.
  • array_combinations returns an iterator over K length combinations of all the elements in the underlying iterator.
  • array_combinations_with_reps returns an iterator over K length combinations with repetitions/replacements of all the elements in the underlying iterator.
  • cartesian_product returns an iterator over the cartesian product of the element sets of two iterators.
  • circular_array_windows returns an iterator over all contiguous windows of length N that wraps around at the end.
  • combinations returns an iterator over k length combinations of all the elements in the underlying iterator.
  • combinations_with_reps returns an iterator over k length combinations with repetitions/replacements of all the elements in the underlying iterator.

License

This project is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE and LICENSE-MIT for details.

Dependencies