Function Subspace :: sus :: iter :: repeat_with

template <class Item, class RepeatFn>
auto repeat_with(RepeatFn repeater) -> RepeatWith<Item, RepeatFn>
requires
sus::fn::FnMut<RepeatFn, Item (void)>

Creates a new iterator that repeats elements of type Item endlessly by applying the provided closure, the repeater, FnMut<Item()>.

The repeat_with function calls the repeater over and over again. Infinite iterators like repeat_with are often used with adapters like Iterator::take(), in order to make them finite.

If the element type of the iterator you need implements Clone, and it is OK to keep the source element in memory, you should instead use the repeat function.

Exampler

auto r = sus::iter::repeat_with<u16>([] { return 3_u16; });
sus_check(r.next().unwrap() == 3_u16);
sus_check(r.next().unwrap() == 3_u16);
sus_check(r.next().unwrap() == 3_u16);