pub struct Stream<'a, Sig> { /* private fields */ }
Expand description
A stream of signals.
A stream represents a composable signal producer. When you decide to send a signal down a
stream, any other streams composed with that first stream will also receive the signal. This
enables to construct more interesting and complex streams by composing them via, for instance,
Stream::map
, Stream::filter_map
, Stream::filter
, Stream::fold
,
Stream::merge
, Stream::zip
, etc.
Implementations§
Source§impl<'a, Sig> Stream<'a, Sig>
impl<'a, Sig> Stream<'a, Sig>
Sourcepub fn observe<F>(&self, subscriber: F) -> u128
pub fn observe<F>(&self, subscriber: F) -> u128
Observe a stream signal output flowing out of the stream.
Do not abuse this function, as its primary use is to build other combinators.
Sourcepub fn observe_with_handle<F>(&self, subscriber: F, handle_id: u128)
pub fn observe_with_handle<F>(&self, subscriber: F, handle_id: u128)
Observe a stream signal output flowing out of the stream.
Do not abuse this function, as its primary use is to build other combinators.
Sourcepub fn map<F, OutSig>(&self, f: F) -> Stream<'a, OutSig>
pub fn map<F, OutSig>(&self, f: F) -> Stream<'a, OutSig>
Map any signals flowing out of a stream.
Please note that this function is total: you cannot ignore signals. Even if you map
uninteresting signals to None
, you’ll still compose signals for those. If you’re interested
in filtering signals while mapping, have a look at the Stream::filter_map
function.
Sourcepub fn filter_map<F, OutSig>(&self, f: F) -> Stream<'a, OutSig>
pub fn filter_map<F, OutSig>(&self, f: F) -> Stream<'a, OutSig>
Filter and map signals flowing out of a stream.
If you’re not interested in a specific signal, you can emit None
: no signal will be sent.
Sourcepub fn filter<F>(&self, pred: F) -> Self
pub fn filter<F>(&self, pred: F) -> Self
Filter the signals flowing out of a stream with a predicate.
Sourcepub fn fold<F, A>(&self, value: A, f: F) -> Stream<'a, A>
pub fn fold<F, A>(&self, value: A, f: F) -> Stream<'a, A>
Fold all signals flowing out of a stream into a stream of values.
Sourcepub fn merge(&self, rhs: &Self) -> Self
pub fn merge(&self, rhs: &Self) -> Self
Merge two streams into one.
Merging streams enables you to perform later useful compositions, such as folding the merged results.
Sourcepub fn merge_with<F, SigRHS>(
&self,
rhs: &Stream<'a, SigRHS>,
adapter: F,
) -> Self
pub fn merge_with<F, SigRHS>( &self, rhs: &Stream<'a, SigRHS>, adapter: F, ) -> Self
Merge two streams into one with incompatible types.
This method performs the same logical operation as:
use reactive_graph_reactive_model_impl::Stream;
let stream_a = Stream::new();
let stream_b = Stream::new();
let merged = stream_a.merge(&stream_b.map(String::len));
However, because it does it in a more optimal way, you are advised to use this combinator instead.
Sourcepub fn zip<SigRHS>(
&self,
rhs: &Stream<'a, SigRHS>,
) -> Stream<'a, Either<Sig, SigRHS>>
pub fn zip<SigRHS>( &self, rhs: &Stream<'a, SigRHS>, ) -> Stream<'a, Either<Sig, SigRHS>>
Zip two streams with each other.
The resulting stream will output Either
from one or the other stream.
Sourcepub fn entangled<F, G, GSig>(f: F, g: G) -> (Self, Stream<'a, GSig>)
pub fn entangled<F, G, GSig>(f: F, g: G) -> (Self, Stream<'a, GSig>)
Create a pair of entangled streams.
If any of the streams sends a signal, the other one receives it. However, be careful: since
the signals are defined in terms of each other, it’s quite easy to cause infinite loops if you
don’t have a well-defined bottom to your recursion. This is why you’re expected to return
Option<_>
signals.
Source§impl<'a, SigA, SigB> Stream<'a, Either<SigA, SigB>>
impl<'a, SigA, SigB> Stream<'a, Either<SigA, SigB>>
Sourcepub fn unzip(&self) -> (Stream<'a, SigA>, Stream<'a, SigB>)
pub fn unzip(&self) -> (Stream<'a, SigA>, Stream<'a, SigB>)
Split a stream of zipped values into two streams.
If the Either::Left
part of the stream emits a signal, it is sent to the first stream.
If the Either::Right
part of the tream emits, it is sent to the second stream.
Trait Implementations§
impl<Sig> Send for Stream<'_, Sig>
TODO: This solves many problems, but is it really OK?
impl<Sig> Sync for Stream<'_, Sig>
Auto Trait Implementations§
impl<'a, Sig> !Freeze for Stream<'a, Sig>
impl<'a, Sig> RefUnwindSafe for Stream<'a, Sig>
impl<'a, Sig> Unpin for Stream<'a, Sig>
impl<'a, Sig> UnwindSafe for Stream<'a, Sig>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more