sorted-iter provides set and relational operations for all iterators in the standard library that are known at compile time to be sorted.
Set operations example
For iterators that are known to be sorted by item, it provides set operations that itself return iterators:
use sorted_iter::SortedIterator;
// the iterator returned by BTreeSet::into_iter is known at compile time to be sorted by item
let primes = btreeset! { 2, 3, 5, 7, 11, 13u64 }.into_iter();
let fibs = btreeset! { 1, 2, 3, 5, 8, 13u64 }.into_iter();
// compute the intersection of the two sorted iterators, as another iterator
let fib_primes = primes.intersection(fibs);
Relational operations example
For iterators of pairs that are known to be sorted by key, it provides relational operations that itself return iterators:
use sorted_iter::SortedPairIterator;
// the iterator returned by BTreeMap::into_iter is known at compile time to be sorted by key
let cities = btreemap! {
1 => "New York",
2 => "Tokyo",
3u8 => "Berlin"
}.into_iter();
let countries = btreemap! {
1 => "USA",
2 => "Japan",
3u8 => "Germany"
}.into_iter();
// compute an inner join of cities and countries, returning an iterator
let cities_and_countries = cities.join(countries);
Combinators that preserve sort order are properly considered. E.g. filtering a sorted iterator is guaranteed to again yield a sorted iterator.
I hope somebody will find this useful, either for the functionality it provides or as a complex example for defining extension traits.
Cheers,
RĂĽdiger