Struct sodium::Stream

source ·
pub struct Stream<A> {
    pub impl_: Stream<A>,
}
Expand description

Represents a stream of discrete events/firings containing values of type A.

Also known in other FRP systems as an event (which would contain event occurrences), an event stream, an observable, or a signal.

Fields§

§impl_: Stream<A>

Implementations§

source§

impl<A: Clone + Send + 'static> Stream<Option<A>>

source

pub fn filter_option(&self) -> Stream<A>

Return a Stream that only outputs events that have present values, removing the Option wrapper and discarding empty values.

source§

impl<A: Clone + Send + Sync + 'static, COLLECTION: IntoIterator<Item = A> + Clone + Send + 'static> Stream<COLLECTION>

source

pub fn split(&self) -> Stream<A>

Flatten a Stream of a collection of A into a Stream of single As.

source§

impl<A: Clone + Send + 'static> Stream<A>

source

pub fn new(sodium_ctx: &SodiumCtx) -> Stream<A>

Create a Stream that will never fire.

source

pub fn snapshot<B: Clone + Send + 'static, C: Clone + Send + 'static, FN: IsLambda2<A, B, C> + Send + Sync + 'static>( &self, cb: &Cell<B>, f: FN ) -> Stream<C>

Return a stream whose events are the result of the combination of the event value and the current value of the cell using the specified function.

Note that there is an implicit delay: state updates caused by event firings being held with Stream::hold don’t become visible as the cell’s current value until the following transaction. To put this another way, snapshot always sees the value of a cell as it wass before any state changes from the current transaction.

source

pub fn snapshot1<B: Send + Clone + 'static>(&self, cb: &Cell<B>) -> Stream<B>

A variant of snapshot that captures the cell’s value at the time of the event firing, ignoring the stream’s value.

source

pub fn snapshot3<B: Send + Clone + 'static, C: Send + Clone + 'static, D: Send + Clone + 'static, FN: IsLambda3<A, B, C, D> + Send + Sync + 'static>( &self, cb: &Cell<B>, cc: &Cell<C>, f: FN ) -> Stream<D>

A variant of snapshot that captures the value of two cells.

source

pub fn snapshot4<B: Send + Clone + 'static, C: Send + Clone + 'static, D: Send + Clone + 'static, E: Send + Clone + 'static, FN: IsLambda4<A, B, C, D, E> + Send + Sync + 'static>( &self, cb: &Cell<B>, cc: &Cell<C>, cd: &Cell<D>, f: FN ) -> Stream<E>

A variant of snapshot that captures the value of three cells.

source

pub fn snapshot5<B: Send + Clone + 'static, C: Send + Clone + 'static, D: Send + Clone + 'static, E: Send + Clone + 'static, F: Send + Clone + 'static, FN: IsLambda5<A, B, C, D, E, F> + Send + Sync + 'static>( &self, cb: &Cell<B>, cc: &Cell<C>, cd: &Cell<D>, ce: &Cell<E>, f: FN ) -> Stream<F>

A variant of snapshot that captures the value of four cells.

source

pub fn snapshot6<B: Send + Clone + 'static, C: Send + Clone + 'static, D: Send + Clone + 'static, E: Send + Clone + 'static, F: Send + Clone + 'static, G: Send + Clone + 'static, FN: IsLambda6<A, B, C, D, E, F, G> + Send + Sync + 'static>( &self, cb: &Cell<B>, cc: &Cell<C>, cd: &Cell<D>, ce: &Cell<E>, cf: &Cell<F>, f: FN ) -> Stream<G>

A variant of snapshot that captures the value of five cells.

source

pub fn map<B: Send + Clone + 'static, FN: IsLambda1<A, B> + Send + Sync + 'static>( &self, f: FN ) -> Stream<B>

Transform this Stream’s event values with the supplied function.

The supplied function may construct FRP logic or use Cell::sample, in which case it’s equivalent to snapshoting the cell. In addition, the function must be referentially transparent.

source

pub fn map_to<B: Send + Sync + Clone + 'static>(&self, b: B) -> Stream<B>

Transform this Stream’s event values into the specified constant value.

source

pub fn filter<PRED: IsLambda1<A, bool> + Send + Sync + 'static>( &self, pred: PRED ) -> Stream<A>

Return a Stream that only outputs events for which the predicate returns true.

source

pub fn or_else(&self, s2: &Stream<A>) -> Stream<A>

Variant of merge that merges two streams.

In the case where two events are simultaneous (both in the same transaction), the event taken from self takes precedenc, and the event from s2 will be dropped.

If you want to specify your own combining function use merge. This function is equivalent to s1.merge(s2, |l, _r| l). The name or_else is used instead of merge to make it clear that care should be taken because events can be dropped.

source

pub fn merge<FN: IsLambda2<A, A, A> + Send + Sync + 'static>( &self, s2: &Stream<A>, f: FN ) -> Stream<A>

Merge two streams of the same type into one, so that events on either input appear on the returned stream.

If the events are simultaneous (that is, one event from self and one from s2 occur in the same transaction), combine them into one using the specified combining function so that the returned stream is guaranteed only ever to have one event per transaction. The event from self will appear at the left input of the combining function, and the event from s2 will appear at the right.

source

pub fn hold(&self, a: A) -> Cell<A>

Returns a cell with the specified initial value, which is updated by this stream’s event values.

source

pub fn hold_lazy(&self, a: Lazy<A>) -> Cell<A>

A variant of hold that uses an initial value returned by Cell::sample_lazy.

source

pub fn gate(&self, cpred: &Cell<bool>) -> Stream<A>

Return a stream that only outputs events from the input stream when the specified cell’s value is true.

source

pub fn once(&self) -> Stream<A>

Return a stream that outputs only one value, which is the next event of the input stream, starting from the transaction in once was invoked.

source

pub fn collect<B, S, F>(&self, init_state: S, f: F) -> Stream<B>
where B: Send + Clone + 'static, S: Send + Clone + 'static, F: IsLambda2<A, S, (B, S)> + Send + Sync + 'static,

Transform an event with a generalized state loop (a Mealy machine). The function is passed the input and the old state and returns the new state and output value.

source

pub fn collect_lazy<B, S, F>(&self, init_state: Lazy<S>, f: F) -> Stream<B>
where B: Send + Clone + 'static, S: Send + Clone + 'static, F: IsLambda2<A, S, (B, S)> + Send + Sync + 'static,

A variant of collect that takes an initial state that is returned by Cell::sample_lazy.

source

pub fn accum<S, F>(&self, init_state: S, f: F) -> Cell<S>
where S: Send + Clone + 'static, F: IsLambda2<A, S, S> + Send + Sync + 'static,

Accumulate on an input event, outputting the new state each time.

As each event is received, the accumulating function f is called with the current state and the new event value. The accumulating function may construct FRP logic or use Cell::sample, in which case it’s equivalent to snapshoting the cell. In additon, the function must be referentially transparent.

source

pub fn accum_lazy<S, F>(&self, init_state: Lazy<S>, f: F) -> Cell<S>
where S: Send + Clone + 'static, F: IsLambda2<A, S, S> + Send + Sync + 'static,

A variant of accum that takes an initial state returned by Cell::sample_lazy.

source

pub fn listen_weak<K: IsLambda1<A, ()> + Send + Sync + 'static>( &self, k: K ) -> Listener

A variant of listen that will deregister the listener automatically if the listener is garbage-collected.

With listen the listener is only deregistered if Listener::unlisten is called explicitly.

source

pub fn listen<K: IsLambda1<A, ()> + Send + Sync + 'static>( &self, k: K ) -> Listener

Listen for events/firings on this stream.

This is the observer pattern. The returned Listener has an unlisten method to cause the listener to be removed. This is an operational mechanism for interfacing between the world of I/O and FRP.

The handler function for this listener should make no assumptions about what thread it will be called on, and the handler should not block. It also is not allowed to use CellSink::send or StreamSink::send in the handler.

Trait Implementations§

source§

impl<A> Clone for Stream<A>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<A> !RefUnwindSafe for Stream<A>

§

impl<A> Send for Stream<A>
where A: Send,

§

impl<A> Sync for Stream<A>
where A: Send,

§

impl<A> Unpin for Stream<A>

§

impl<A> !UnwindSafe for Stream<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> ToOwned for T
where T: Clone,

§

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

§

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

§

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.