use super::Signal;
pub trait SignalTake: Signal {
fn take(self, n: usize) -> Take<Self>
where
Self: Sized,
{
Take { signal: self, n }
}
}
impl<T> SignalTake for T where T: Signal {}
#[derive(Clone)]
pub struct Take<S>
where
S: Signal,
{
signal: S,
n: usize,
}
impl<S> Iterator for Take<S>
where
S: Signal,
{
type Item = f32;
#[inline]
fn next(&mut self) -> Option<f32> {
if self.n == 0 {
return None;
}
self.n -= 1;
Some(self.signal.next())
}
}