Double-Ended Peekable

version checks docs coverage licence

A very small crate providing an additional abstraction over [Iterator], in order to lift the concepts introduced by [Peekable] over [DoubleEndedIterator].

The reason

With Peekable you can use [peek] in order to get a reference to the upcoming element from the iterator, and you can also use [next_if]/[next_if_eq] in order to advance the iterator only when the upcoming element satisfies some conditions.

However, this abstraction does not work well when you need to perform these operations from both the start and the end of a double-ended iterator. For instance, you cannot just do .by_ref().rev().peekable().peek().next() on the fly, because even if this approach seems to work, the implementation need to store the next element (the corresponding of [next_back], to be clearer) inside the instance of Peekable, which means that the peeked element is going to be dropped using the snippet just shown.

How to use

You just need to import the extension trait [DoubleEndedPeekableExt] in order to easily use the [double_ended_peekable]:

```rust use doubleendedpeekable::DoubleEndedPeekableExt;

let mut iter = [0, 1, 2, 3, 4].intoiter().doubleendedpeekable(); asserteq!( iter.nextfrontbackif(|a, b| a % 2 == 0 && b % 2 == 0), Some((0, 4)) ); asserteq!(iter.next(), Some(1)); asserteq!(iter.nextback(), Some(3)); asserteq!(iter.peek(), Some(&2)); asserteq!(iter.peekback(), Some(&2)); asserteq!(iter.nextfrontbackifeq(&2, &2), None); asserteq!(iter.next(), Some(2)); asserteq!(iter.next(), None); ```

Keep in mind that [DoubleEndedPeekableExt] is implemented for every [Iterator], but some of the methods of [DoubleEndedPeekable] are only implemented for types that implement [DoubleEndedIterator].

Features