Crate dedup_iter [] [src]

This crate provides a couple of iterator adapters for deduplication of elements from a source iterator, inspired by the dedup methods in Vec.

dedup

The DedupAdapter is an iterator adapter that removes consecutive repeated elements from the source iterator. The dedup trait method returns a Dedup iterator struct.

Example

use dedup_iter::DedupAdapter;

assert_eq!("abcdefe", "aabbccdddeeeeffffeee".chars().dedup().collect::<String>());

dedup_by

The DedupByAdapter is an iterator adapter that removes consecutive repeated elements from the source iterator using a function to determine equality. The dedup_by trait method returns a DedupBy iterator struct.

Examples

use std::ascii::AsciiExt;
use dedup_iter::DedupByAdapter;

assert_eq!(
       "This string had way too much redundant whitespace!",
       "This  string   had      way too     much redundant \n whitespace!".chars()
        .dedup_by(|a, b| a.is_whitespace() && b.is_whitespace() )
        .collect::<String>()
       );

dedup_by_key

The DedupByKeyAdapter is an iterator adapter that removes consecutive repeated elements from the source iterator using a key to determine equality. The dedup_by_key trait method returns a DedupByKey iterator struct.

Examples

use dedup_iter::DedupByKeyAdapter;

assert_eq!(
       "abcdefe",
       "aabbccdddeeeeffffeee".chars()
        .dedup_by_key(|a| *a as usize)
        .collect::<String>()
       );

Structs

Dedup

An iterator that removes elements that are the same as previous one.

DedupBy

An iterator that removes elements that are the same as previous one, according the provided function.

DedupByKey

An iterator that removes elements that have a key that is the same as the key of previous element. The client provided function computes the key.

Traits

DedupAdapter

Provides the dedup method on Iterators.

DedupByAdapter

Provides the dedup_by method on Iterators.

DedupByKeyAdapter

Provides the dedup_by_key method on Iterators.