[][src]Struct frappe::stream::Stream

pub struct Stream<T> { /* fields omitted */ }

A stream of discrete events sent over time.

Methods

impl<T> Stream<T>[src]

pub fn never() -> Self[src]

Creates a stream that never fires.

pub fn observe<F, R>(&self, f: F) where
    F: Fn(MaybeOwned<T>) -> R + Send + Sync + 'static,
    R: ObserveResult
[src]

Reads the values from the stream.

This method registers a callback that will be called every time a stream event is received. It is meant to be used as a debugging tool or as a way to interface with imperative code.

The closure will be dropped when it returns a false-y value (see ObserveResult) or when the source stream is dropped, so you should avoid calling Stream::observe as the last step of a stream chain.

pub fn observe_strong<F, R>(&self, f: F) where
    F: Fn(MaybeOwned<T>) -> R + Send + Sync + 'static,
    T: 'static,
    R: ObserveResult
[src]

Observes the stream while keeping a reference to it.

This is the same as Stream::observe, but it keeps a strong reference to it's source stream, so it's safe to call it as the last step of a stream chain. The closure lifetime only depends on it's return value.

Warning

This creates a cyclic Arc reference that can only be broken by the closure signaling it's deletion (via ObserveResult), so if the closure never unregisters itself it will leak memory.

pub fn inspect<F, R>(self, f: F) -> Self where
    F: Fn(MaybeOwned<T>) -> R + Send + Sync + 'static,
    R: ObserveResult
[src]

Chainable version of Stream::observe.

impl<T: 'static> Stream<T>[src]

pub fn map<F, R>(&self, f: F) -> Stream<R> where
    F: Fn(MaybeOwned<T>) -> R + Send + Sync + 'static,
    R: 'static, 
[src]

Maps this stream into another stream using the provided function.

The closure will be called every time a stream event is received.

pub fn filter<F>(&self, pred: F) -> Self where
    F: Fn(&T) -> bool + Send + Sync + 'static, 
[src]

Creates a new stream that only contains the values where the predicate is true.

pub fn filter_map<F, R>(&self, f: F) -> Stream<R> where
    F: Fn(MaybeOwned<T>) -> Option<R> + Send + Sync + 'static,
    R: 'static, 
[src]

Does filter and map on a stream simultaneously.

The output stream will only contain the unwrapped Some values returned by the closure.

pub fn merge(&self, other: &Stream<T>) -> Self[src]

Creates a new stream that fires with the events from both streams.

pub fn merge_with<U, F1, F2, R>(
    &self,
    other: &Stream<U>,
    f1: F1,
    f2: F2
) -> Stream<R> where
    F1: Fn(MaybeOwned<T>) -> R + Send + Sync + 'static,
    F2: Fn(MaybeOwned<U>) -> R + Send + Sync + 'static,
    U: 'static,
    R: 'static, 
[src]

Merges two streams of different types using two functions.

The first function will be called when receiving events on self, and the second one when receiving events from other. Their combined values will be used to form a stream of a single type.

pub fn merge_with_either<U, F, R>(&self, other: &Stream<U>, f: F) -> Stream<R> where
    F: Fn(Either<MaybeOwned<T>, MaybeOwned<U>>) -> R + Clone + Send + Sync + 'static,
    U: 'static,
    R: 'static, 
[src]

Merges two streams of different types using a single function that takes an Either argument.

Events from self will produce an Either::Left, and events from other will produce an Either::Right.

pub fn fold<A, F>(&self, initial: A, f: F) -> Signal<A> where
    F: Fn(A, MaybeOwned<T>) -> A + Send + Sync + 'static,
    A: Clone + Send + Sync + 'static, 
[src]

Accumulates the values sent over this stream.

The fold operation is done by taking the accumulator, consuming it's value, and then putting back the transformed value. This avoids cloning, but if the closure panics it will leave the storage empty, and then any sampling attempt on this object will panic until someone puts back a value on it. If this is undesirable, use Stream::fold_clone instead.

pub fn fold_clone<A, F>(&self, initial: A, f: F) -> Signal<A> where
    F: Fn(A, MaybeOwned<T>) -> A + Send + Sync + 'static,
    A: Clone + Send + Sync + 'static, 
[src]

Folds the stream by cloning the accumulator.

This does the same as Stream::fold but it will clone the accumulator on every value processed. If the closure panics, the storage will remain unchanged and later attempts at sampling will succeed like nothing happened.

pub fn map_n<F, R>(&self, f: F) -> Stream<R> where
    F: Fn(MaybeOwned<T>, Sender<R>) + Send + Sync + 'static,
    R: 'static, 
[src]

Maps each stream event to 0..N output values.

On every stream event received the closure must return its value by sending it through the provided Sender. Multiple values (or none) can be sent to the output stream this way.

This primitive is useful to construct asynchronous operations, since you can store the Sender and then use it when the data is ready.

pub fn scan<A, F>(&self, initial: A, f: F) -> Stream<A> where
    F: Fn(A, MaybeOwned<T>) -> A + Send + Sync + 'static,
    A: Clone + Send + Sync + 'static, 
[src]

Folds the stream and returns the accumulator values as a stream.

This is the equivalent of doing stream.fold(initial, f).snapshot(&stream, |a, _| a), but more efficient.

pub fn scan_n<A, F, R>(&self, initial: A, f: F) -> Stream<R> where
    F: Fn(A, MaybeOwned<T>, Sender<R>) -> A + Send + Sync + 'static,
    A: Send + Sync + 'static,
    R: 'static, 
[src]

Folds the stream and returns 0..N output values.

The closure must process the input state A, send a value to the output stream using the provided Sender and then return a new state. Multiple values (or none) can be sent to the output stream this way.

pub fn collect<C>(&self) -> Signal<C> where
    C: Default + Extend<T> + Clone + Send + Sync + 'static,
    T: Clone
[src]

Creates a collection from the values sent to this stream.

pub fn element_at(&self, index: usize) -> Self[src]

Returns a stream that contains only the Nth value from the input stream.

pub fn elements_between<B>(&self, range: B) -> Self where
    B: RangeBounds<usize> + Send + Sync + 'static, 
[src]

Returns a stream that contains the values with index in the specified range.

impl<T: Clone + Send + 'static> Stream<T>[src]

pub fn hold(&self, initial: T) -> Signal<T> where
    T: Sync
[src]

Creates a Signal that holds the last value sent to this stream.

pub fn hold_if<F>(&self, initial: T, pred: F) -> Signal<T> where
    F: Fn(&T) -> bool + Send + Sync + 'static,
    T: Sync
[src]

Holds the last value in this stream where the predicate is true.

pub fn zip<U>(&self, other: &Stream<U>) -> Stream<(T, U)> where
    U: Clone + Send + 'static, 
[src]

Collects all pairs of values from two streams.

This creates a Stream of tuples containing each of self's values and other's values in chronological order. An unique value from both streams is required to send a result to the output stream.

pub fn zip_with<U, F, R>(&self, other: &Stream<U>, f: F) -> Stream<R> where
    F: Fn(T, U) -> R + Clone + Send + Sync + 'static,
    U: Clone + Send + 'static,
    R: 'static, 
[src]

Zips two streams using a custom function.

pub fn combine<U>(&self, other: &Stream<U>) -> Stream<(T, U)> where
    U: Clone + Send + 'static, 
[src]

Collects pairs of values from two streams using their last value seen.

This creates a Stream that sends the last value of self and other when either of those receives a value. The stream values before calling this function aren't known, so to send the first output value it's required that both input streams send their initial value.

pub fn combine_with<U, F, R>(&self, other: &Stream<U>, f: F) -> Stream<R> where
    F: Fn(T, U) -> R + Clone + Send + Sync + 'static,
    U: Clone + Send + 'static,
    R: 'static, 
[src]

Combines two streams using a custom function.

impl<T: Clone + 'static> Stream<Option<T>>[src]

pub fn filter_some(&self) -> Stream<T>[src]

Filters a stream of Option, returning only the unwrapped Some values.

impl<T: Clone + 'static, E: Clone + 'static> Stream<Result<T, E>>[src]

pub fn filter_ok(&self) -> Stream<T>[src]

Filters a stream of Result, returning only the unwrapped Ok values.

pub fn filter_err(&self) -> Stream<E>[src]

Filters a stream of Result, returning only the unwrapped Err values.

impl<T: SumType2 + Clone + 'static> Stream<T> where
    T::Type1: 'static,
    T::Type2: 'static, 
[src]

pub fn filter_first(&self) -> Stream<T::Type1>[src]

Creates a stream with only the first element of a sum type.

pub fn filter_second(&self) -> Stream<T::Type2>[src]

Creates a stream with only the second element of a sum type.

pub fn split(&self) -> (Stream<T::Type1>, Stream<T::Type2>)[src]

Splits a two element sum type stream into two streams with the unwrapped values.

impl<T: 'static> Stream<Stream<T>>[src]

pub fn switch(&self) -> Stream<T>[src]

Listens to the events from the last stream sent to a nested stream.

Trait Implementations

impl<T> Clone for Stream<T>[src]

fn clone(&self) -> Self[src]

Creates a copy of this stream that references the same event chain.

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<T> Default for Stream<T>[src]

fn default() -> Self[src]

Creates a stream that never fires.

impl<T: Debug> Debug for Stream<T>[src]

Auto Trait Implementations

impl<T> Send for Stream<T>

impl<T> Sync for Stream<T>

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Erased for T