Skip to main content

Stream

Struct Stream 

Source
pub struct Stream<E, A> { /* private fields */ }
Expand description

An effectful stream producing values of type A.

Pull-based: each step is an Io that produces either the next value and the rest of the stream, or None.

Implementations§

Source§

impl<E: Send + 'static, A: Send + 'static> Stream<E, A>

Source

pub fn empty() -> Self

An empty stream.

Source

pub fn emit(a: A) -> Self

A stream that emits a single value.

Source

pub fn from_vec(items: Vec<A>) -> Self

Build a stream from a Vec of values.

Source

pub fn unfold<S: Send + 'static>( init: S, step: Arc<dyn Fn(S) -> Io<E, Option<(A, S)>> + Send + Sync>, ) -> Self

Build a stream by repeatedly applying a step function to state.

The step function returns None to end the stream, or Some((value, next_state)) to emit and continue.

Source

pub fn from_io(io: Io<E, A>) -> Self

Lift a single Io into a one-element stream.

Source

pub fn map<B: Send + 'static>( self, f: Arc<dyn Fn(A) -> B + Send + Sync>, ) -> Stream<E, B>

Apply a function to each element.

Source

pub fn concat(self, other: Stream<E, A>) -> Self

Append another stream after this one.

Source

pub fn take(self, n: usize) -> Self

Take at most n elements.

Source

pub fn fold<B: Send + 'static>( self, init: B, f: Arc<dyn Fn(B, A) -> B + Send + Sync>, ) -> Io<E, B>

Collapse the stream into a single value via a folding function.

This is the primary way to “run” a stream, producing an Io.

Source

pub fn collect(self) -> Io<E, Vec<A>>

Collect all stream elements into a Vec.

Auto Trait Implementations§

§

impl<E, A> Freeze for Stream<E, A>

§

impl<E, A> !RefUnwindSafe for Stream<E, A>

§

impl<E, A> Send for Stream<E, A>

§

impl<E, A> !Sync for Stream<E, A>

§

impl<E, A> Unpin for Stream<E, A>

§

impl<E, A> UnsafeUnpin for Stream<E, A>

§

impl<E, A> !UnwindSafe for Stream<E, A>

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> 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, 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.