[−][src]Struct frappe::stream::Stream
A stream of discrete events sent over time.
Implementations
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]
F: Fn(MaybeOwned<T>) -> R + Send + Sync + 'static,
R: ObserveResult,
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]
F: Fn(MaybeOwned<T>) -> R + Send + Sync + 'static,
T: 'static,
R: ObserveResult,
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]
F: Fn(MaybeOwned<T>) -> R + Send + Sync + 'static,
R: ObserveResult,
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]
F: Fn(MaybeOwned<T>) -> R + Send + Sync + 'static,
R: 'static,
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]
F: Fn(&T) -> bool + Send + Sync + 'static,
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]
F: Fn(MaybeOwned<T>) -> Option<R> + Send + Sync + 'static,
R: 'static,
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]
&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,
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]
F: Fn(Either<MaybeOwned<T>, MaybeOwned<U>>) -> R + Clone + Send + Sync + 'static,
U: 'static,
R: 'static,
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]
F: Fn(A, MaybeOwned<T>) -> A + Send + Sync + 'static,
A: Clone + Send + Sync + 'static,
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]
F: Fn(A, MaybeOwned<T>) -> A + Send + Sync + 'static,
A: Clone + Send + Sync + 'static,
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]
F: Fn(MaybeOwned<T>, Sender<R>) + Send + Sync + 'static,
R: 'static,
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]
F: Fn(A, MaybeOwned<T>) -> A + Send + Sync + 'static,
A: Clone + Send + Sync + 'static,
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]
F: Fn(A, MaybeOwned<T>, Sender<R>) -> A + Send + Sync + 'static,
A: Send + Sync + 'static,
R: 'static,
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]
C: Default + Extend<T> + Clone + Send + Sync + 'static,
T: Clone,
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]
B: RangeBounds<usize> + Send + Sync + 'static,
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]
T: Sync,
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]
F: Fn(&T) -> bool + Send + Sync + 'static,
T: Sync,
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]
U: Clone + Send + 'static,
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]
F: Fn(T, U) -> R + Clone + Send + Sync + 'static,
U: Clone + Send + 'static,
R: 'static,
Zips two streams using a custom function.
pub fn combine<U>(&self, other: &Stream<U>) -> Stream<(T, U)> where
U: Clone + Send + 'static,
[src]
U: Clone + Send + 'static,
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]
F: Fn(T, U) -> R + Clone + Send + Sync + 'static,
U: Clone + Send + 'static,
R: 'static,
Combines two streams using a custom function.
pub fn next(&self) -> StreamFuture<T>
[src]
Creates a future that returns the next value sent to this stream.
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]
T::Type1: 'static,
T::Type2: 'static,
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]
impl<T: Debug> Debug for Stream<T>
[src]
impl<T> Default for Stream<T>
[src]
Auto Trait Implementations
impl<T> !RefUnwindSafe for Stream<T>
impl<T> Send for Stream<T>
impl<T> Sync for Stream<T>
impl<T> Unpin for Stream<T>
impl<T> !UnwindSafe for Stream<T>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Erased for T
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,