Expand description
steepen
is a crate used to convert an iterator of elements into an iterator of blocks, given
that blocks can be created from an iterator of elements.
Does the contrary of the flatten
function, hence the name.
§Examples
use steepen::Steepenable;
let iter = vec![("a", 1),("a", 2),("b", 1),("b", 2),("b", 1),("c", 2)].into_iter();
let mut result = iter
.steepen_by::<Vec<(&str, u32)>, _>(
// letters are different or numbers are descending
|x, y| x.0 != y.0 || x.1 > y.1
);
assert_eq!(result.next(), Some(vec![("a", 1),("a", 2)]));
assert_eq!(result.next(), Some(vec![("b", 1),("b", 2)]));
assert_eq!(result.next(), Some(vec![("b", 1)]));
assert_eq!(result.next(), Some(vec![("c", 2)]));
assert_eq!(result.next(), None);
§Properties
iterators returned by a steepen
function respect four principles:
- It won’t be empty
- Elements remain in order, i.e a
flatten
function reverses it - Last element of an iterator and first element of the next iterator respect the predicate
- every pair of consecutive element in an iterator don’t respect the predicate
Structs§
- Separate
- Iterator struct that injects
None
values between elements according to a separator. - Steepen
- Iterator that yield blocks of elements in ascending order.
- Steepen
By - Iterator that yields blocks of elements separated by a predicate.
- Steepen
Eq - Iterator that yields blocks of equal elements.
- Steepen
Strict - Iterator that yields blocks of strictly ascending elements.
Traits§
- Separable
- Trait to add
separate
function - Steepenable
- Trait to add
steepen
functions