Function itertools::repeat_call

source ·
pub fn repeat_call<F, A>(function: F) -> RepeatCall<F> 
where F: FnMut() -> A,
👎Deprecated since 0.8: Use std repeat_with() instead
Expand description

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]