Skip to main content

LazyStream

Struct LazyStream 

Source
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>

Source

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.

Source

pub fn constant(val: T) -> Self

Create the constant stream [val, val, val, ...].

Source

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.

Source

pub fn take(&self, n: usize) -> Vec<T>

Return the first n elements of the stream.

Source

pub fn nth(&self, n: usize) -> T

Return the n-th element (0-indexed).

Source

pub fn map<U: Clone, F: Fn(&T) -> U>(&self, f: F) -> LazyStream<U>

Apply f element-wise, producing a new LazyStream<U>.

Source

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
Source

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>

Source§

fn clone(&self) -> LazyStream<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Clone> Debug for LazyStream<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: PartialEq + Clone> PartialEq for LazyStream<T>

Source§

fn eq(&self, other: &LazyStream<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Eq + Clone> Eq for LazyStream<T>

Source§

impl<T: Clone> StructuralPartialEq for LazyStream<T>

Auto Trait Implementations§

§

impl<T> Freeze for LazyStream<T>

§

impl<T> RefUnwindSafe for LazyStream<T>
where T: RefUnwindSafe,

§

impl<T> Send for LazyStream<T>
where T: Send,

§

impl<T> Sync for LazyStream<T>
where T: Sync,

§

impl<T> Unpin for LazyStream<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for LazyStream<T>

§

impl<T> UnwindSafe for LazyStream<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Setoid for T
where T: PartialEq,

Source§

fn equiv(&self, other: &T) -> bool

The equivalence relation.
Source§

fn refl(&self) -> bool

Reflexivity of the equivalence.
Source§

fn symm(&self, other: &Self) -> bool

Symmetry: if self ~ other then other ~ self.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.