Function Subspace :: sus :: iter :: repeat

template <class Item>
auto repeat(Item item) -> Repeat<Item>
requires
sus::mem::Clone<Item>

Creates a new iterator that endlessly repeats a single element.

The repeat function repeats a single value over and over again. Infinite iterators like repeat are often used with adapters like Iterator::take(), in order to make them finite.

If the element type of the iterator you need does not implement Clone, or if you do not want to keep the repeated element in memory, you can instead use the repeat_with function.

Example

auto r = sus::iter::repeat<u16>(3u);
sus_check(r.next().unwrap() == 3_u16);
sus_check(r.next().unwrap() == 3_u16);
sus_check(r.next().unwrap() == 3_u16);