dedup_iter 0.1.1

Deduplicating iterator adapters
Documentation
  • Coverage
  • 70%
    7 out of 10 items documented1 out of 10 items with examples
  • Size
  • Source code size: 11.23 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 4.45 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • aswaving/dedup_iter
    4 0 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • aswaving

Build Status

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 DedupIteratorAdapter is an iterator adapter that removes consecutive repeated elements from the source iterator. The dedup trait method of DedupIteratorAdapter returns a DedupIterator.

Example

use dedup_iter::DedupIteratorAdapter;

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!(
    "F I F O",
    "First In, First Out".chars()
     .dedup_by_key(|a| a.is_whitespace())
     .collect::<String>()
);