Function malachite_base::iterators::comparison::delta_directions
source · pub const fn delta_directions<I: Iterator>(xs: I) -> DeltaDirections<I> ⓘ
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
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(),
&[Less, Greater, Less, Greater, Greater]
)