orx_iterable/sources/
repeat_n.rs

1use crate::Iterable;
2
3/// An iterable which yields the same value `n` times.
4pub struct RepeatN<T>
5where
6    T: Clone,
7{
8    pub(crate) value: T,
9    pub(crate) count: usize,
10}
11
12impl<T> Iterable for RepeatN<T>
13where
14    T: Clone,
15{
16    type Item = T;
17
18    type Iter = core::iter::RepeatN<T>;
19
20    fn iter(&self) -> Self::Iter {
21        core::iter::repeat_n(self.value.clone(), self.count)
22    }
23}
24
25impl<T> Iterable for core::iter::RepeatN<T>
26where
27    T: Clone,
28{
29    type Item = T;
30
31    type Iter = core::iter::RepeatN<T>;
32
33    fn iter(&self) -> Self::Iter {
34        self.clone()
35    }
36}
37
38/// Creates an iterable which yields the same value `n` times.
39pub fn repeat_n<T>(value: T, count: usize) -> RepeatN<T>
40where
41    T: Clone,
42{
43    RepeatN { value, count }
44}