Function itertools::intersperse_with[][src]

pub fn intersperse_with<I, F>(
    iterable: I,
    element: F
) -> IntersperseWith<I::IntoIter, F>
Notable traits for IntersperseWith<I, ElemF>
impl<I, ElemF> Iterator for IntersperseWith<I, ElemF> where
    I: Iterator,
    ElemF: IntersperseElement<I::Item>, 
type Item = I::Item;
where
    I: IntoIterator,
    F: FnMut() -> I::Item
Expand description

Iterate iterable with a particular value created by a function inserted between each element.

IntoIterator enabled version of Iterator::intersperse_with.

use itertools::intersperse_with;

let mut i = 10;
itertools::assert_equal(intersperse_with((0..3), || { i -= 1; i }), vec![0, 9, 1, 8, 2]);
assert_eq!(i, 8);