Function malachite_base::iterators::comparison::delta_directions
source · [−]pub const fn delta_directions<I: Iterator>(xs: I) -> DeltaDirections<I>ⓘNotable traits for DeltaDirections<I>impl<I: Iterator> Iterator for DeltaDirections<I> where
I::Item: Ord, type Item = Ordering;
where
I::Item: Ord,
Expand description
Returns an iterator that generates the Ordering
s of adjacent pairs of
elements of a given iterator.
To put it another way (at least for types where subtraction is defined), the returned iterator produces the signs of the finite differences of the input iterator.
$f((x_k)_{k=0}^N) = (\operatorname{cmp}(x_k, x_{k-1}))_{k=1}^N$, where $N$ may be $\infty$.
The output length is infinite if xs
is infinite, or $\max(n - 1, 0)$ otherwise, where $n$ is
xs.count()
.
Examples
extern crate itertools;
use itertools::Itertools;
use malachite_base::iterators::comparison::delta_directions;
use std::cmp::Ordering;
assert_eq!(
delta_directions([3, 1, 4, 1, 5, 9].into_iter()).collect_vec(),
&[Ordering::Less, Ordering::Greater, Ordering::Less, Ordering::Greater, Ordering::Greater]
)