Crate itertools [] [src]

Itertools — extra iterator adaptors, functions and macros.

To use the iterator methods in this crate, import the Itertools trait:

use itertools::Itertools;

Some iterators or adaptors are used directly like regular structs, for example PutBack, Zip, Stride, StrideMut.

To use the macros in this crate, use the #[macro_use] attribute:

#[macro_use]
extern crate itertools;

License

Dual-licensed to be compatible with the Rust project.

Licensed under the Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0 or the MIT license http://opensource.org/licenses/MIT, at your option. This file may not be copied, modified, or distributed except according to those terms.

Modules

misc

A module of helper traits and iterators that are not intended to be used directly.

size_hint

Arithmetic on Iterator .size_hint() values.

Macros

icompr!

icompr as in “iterator comprehension” allows creating a mapped iterator with simple syntax, similar to set builder notation, and directly inspired by Python. Supports an optional filter clause.

iproduct!

Create an iterator over the “cartesian product” of iterators.

izip!

Create an iterator running multiple iterators in lockstep.

Structs

Batching

A “meta iterator adaptor”. Its closure recives a reference to the iterator and may pick off as many elements as it likes, to produce the next iterator element.

Coalesce

An iterator adaptor that may join together adjacent elements.

FnMap

A clonable iterator adaptor to map elementwise from one iterator to another, using a function pointer.

GroupBy

An iterator adaptor that groups iterator elements. Consecutive elements that map to the same key (“runs”), are returned as the iterator elements.

ISlice

An iterator adaptor that yields a subset (a slice) of the base iterator.

Interleave

An iterator adaptor that alternates elements from two iterators until both run out.

Intersperse

An iterator adaptor to insert a particular value between each element of the adapted iterator.

Linspace

An iterator of a sequence of evenly spaced floats.

Merge

An iterator adaptor that merges the two base iterators in ascending order. If both base iterators are sorted (ascending), the result is sorted.

MultiPeek

An iterator adaptor that allows the user to peek at multiple .next() values without advancing itself.

Product

An iterator adaptor that iterates over the cartesian product of the element sets of two iterators I and J.

PutBack

An iterator adaptor that allows putting back a single item to the front of the iterator.

RcIter

A wrapper for Rc<RefCell<I>>, that implements the Iterator trait.

RepeatN

An iterator that repeats an element exactly n times.

Step

An iterator adaptor that steps a number elements in the base iterator for each iteration.

Stride

An iterator similar to the slice iterator, but with a certain number of steps (the stride) skipped per iteration.

StrideMut

The mutable equivalent of Stride.

TakeWhileRef

An iterator adaptor that borrows from a Clone-able iterator to only pick off elements while the predicate returns true.

Tee

One half of an iterator pair where both return the same elements.

Times

A simple iterator to repeat a given number of times

Zip

An iterator that generalizes .zip() and allows running multiple iterators in lockstep.

ZipLongest

An iterator which iterates two other iterators simultaneously

Enums

EitherOrBoth

A value yielded by ZipLongest. Contains one or two values, depending on which of the input iterators are exhausted.

Traits

Itertools

The trait Itertools: extra iterator adaptors and methods for iterators.

Functions

equal

Return true if both iterators produce equal sequences (elements pairwise equal and sequences of the same length), false otherwise.

linspace

Return an iterator with n elements, where the first element is a and the last element is b.

times

Return an iterator with n elements, for simple repetition a particular number of times. The iterator yields a counter.

Type Definitions

CoalesceFn

An iterator adaptor that may joins together adjacent elements.

MergeAscend

An ascending order merge iterator created with .merge().