This crate provides a couple of iterator adapters for deduplication from elements of 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
.
```rust use dedup_iter::DedupIteratorAdapter;
assert_eq!("abcdefe", "aabbccdddeeeeffffeee".chars().dedup().collect::
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.
```rust use std::ascii::AsciiExt; use dedup_iter::DedupByAdapter;
asserteq!(
"This string had way too much redundant whitespace!",
"This string had way too much redundant \n whitespace!".chars()
.dedupby(|a, b| a.iswhitespace() && b.iswhitespace() )
.collect::
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.
```rust use dedup_iter::DedupByKeyAdapter;
asserteq!(
"abcdefe",
"aabbccdddeeeeffffeee".chars()
.dedupby_key(|a| *a as usize)
.collect::