pub struct LazyStream<T: Clone> { /* private fields */ }Expand description
A lazy, eventually-periodic stream.
The stream is defined by a finite prefix followed by an infinitely
repeating cycle. If cycle is empty, the stream is exactly prefix
(i.e. finite for practical purposes but the API treats it as an
infinite stream repeating the last element when both slices are exhausted,
which is handled in the accessor functions).
Implementations§
Source§impl<T: Clone> LazyStream<T>
impl<T: Clone> LazyStream<T>
Sourcepub fn new(prefix: Vec<T>, cycle: Vec<T>) -> Self
pub fn new(prefix: Vec<T>, cycle: Vec<T>) -> Self
Create a stream with an explicit prefix and repeating cycle.
If cycle is empty the stream is treated as a finite prefix followed
by an infinite repetition of the last prefix element; if the prefix is
also empty the stream returns the default value if T: Default, but
callers should guarantee cycle is non-empty for infinite streams.
Sourcepub fn cycle(vals: Vec<T>) -> Self
pub fn cycle(vals: Vec<T>) -> Self
Create a stream that repeats vals forever: vals\[0\], vals\[1\], ..., vals[n-1], vals\[0\], ....
Panics if vals is empty.
Sourcepub fn map<U: Clone, F: Fn(&T) -> U>(&self, f: F) -> LazyStream<U>
pub fn map<U: Clone, F: Fn(&T) -> U>(&self, f: F) -> LazyStream<U>
Apply f element-wise, producing a new LazyStream<U>.
Sourcepub fn zip<U: Clone, V: Clone, F: Fn(&T, &U) -> V>(
&self,
other: &LazyStream<U>,
f: F,
) -> LazyStream<V>
pub fn zip<U: Clone, V: Clone, F: Fn(&T, &U) -> V>( &self, other: &LazyStream<U>, f: F, ) -> LazyStream<V>
Point-wise combine two streams with a binary function.
The resulting stream has:
- prefix length = max of the two prefixes, extended by cycling the shorter cycle
- cycle length = lcm of the two cycle lengths
Sourcepub fn to_approx(&self, n: usize) -> StreamApprox<T>
pub fn to_approx(&self, n: usize) -> StreamApprox<T>
Convert the stream to a finite unrolled approximation of depth n.
Trait Implementations§
Source§impl<T: Clone + Clone> Clone for LazyStream<T>
impl<T: Clone + Clone> Clone for LazyStream<T>
Source§fn clone(&self) -> LazyStream<T>
fn clone(&self) -> LazyStream<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more