Function itertools::repeat_call [] [src]

Important traits for RepeatCall<F>
pub fn repeat_call<F, A>(function: F) -> RepeatCall<F> where
    F: FnMut() -> A, 

An iterator source that produces elements indefinitely by calling a given closure.

Iterator element type is the return type of the closure.

use itertools::repeat_call;
use itertools::Itertools;
use std::collections::BinaryHeap;

let mut heap = BinaryHeap::from(vec![2, 5, 3, 7, 8]);

// extract each element in sorted order
for element in repeat_call(|| heap.pop()).while_some() {
    print!("{}", element);

    repeat_call(|| 1).take(5),
    vec![1, 1, 1, 1, 1]