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>>
impl<A: Clone + Send + 'static> Stream<Option<A>>
sourcepub fn filter_option(&self) -> Stream<A>
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>
impl<A: Clone + Send + Sync + 'static, COLLECTION: IntoIterator<Item = A> + Clone + Send + 'static> Stream<COLLECTION>
source§impl<A: Clone + Send + 'static> Stream<A>
impl<A: Clone + Send + 'static> Stream<A>
sourcepub 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>
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.
sourcepub fn snapshot1<B: Send + Clone + 'static>(&self, cb: &Cell<B>) -> Stream<B>
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.
sourcepub 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>
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.
sourcepub 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>
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.
sourcepub 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>
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.
sourcepub 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>
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.
sourcepub fn map<B: Send + Clone + 'static, FN: IsLambda1<A, B> + Send + Sync + 'static>(
&self,
f: FN
) -> Stream<B>
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
snapshot
ing the cell. In addition, the
function must be referentially transparent.
sourcepub fn map_to<B: Send + Sync + Clone + 'static>(&self, b: B) -> Stream<B>
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.
sourcepub fn filter<PRED: IsLambda1<A, bool> + Send + Sync + 'static>(
&self,
pred: PRED
) -> Stream<A>
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
.
sourcepub fn or_else(&self, s2: &Stream<A>) -> Stream<A>
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.
sourcepub fn merge<FN: IsLambda2<A, A, A> + Send + Sync + 'static>(
&self,
s2: &Stream<A>,
f: FN
) -> Stream<A>
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.
sourcepub fn hold(&self, a: A) -> Cell<A>
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.
sourcepub fn hold_lazy(&self, a: Lazy<A>) -> Cell<A>
pub fn hold_lazy(&self, a: Lazy<A>) -> Cell<A>
A variant of hold
that uses an initial value
returned by Cell::sample_lazy
.
sourcepub fn gate(&self, cpred: &Cell<bool>) -> Stream<A>
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.
sourcepub fn once(&self) -> Stream<A>
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.
sourcepub fn collect<B, S, F>(&self, init_state: S, f: F) -> Stream<B>
pub fn collect<B, S, F>(&self, init_state: S, f: F) -> Stream<B>
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.
sourcepub fn collect_lazy<B, S, F>(&self, init_state: Lazy<S>, f: F) -> Stream<B>
pub fn collect_lazy<B, S, F>(&self, init_state: Lazy<S>, f: F) -> Stream<B>
A variant of collect
that takes an
initial state that is returned by Cell::sample_lazy
.
sourcepub fn accum<S, F>(&self, init_state: S, f: F) -> Cell<S>
pub fn accum<S, F>(&self, init_state: S, f: F) -> Cell<S>
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
snapshot
ing the cell. In additon, the
function must be referentially transparent.
sourcepub fn accum_lazy<S, F>(&self, init_state: Lazy<S>, f: F) -> Cell<S>
pub fn accum_lazy<S, F>(&self, init_state: Lazy<S>, f: F) -> Cell<S>
A variant of accum
that takes an initial
state returned by Cell::sample_lazy
.
sourcepub fn listen_weak<K: IsLambda1<A, ()> + Send + Sync + 'static>(
&self,
k: K
) -> Listener
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.
sourcepub fn listen<K: IsLambda1<A, ()> + Send + Sync + 'static>(
&self,
k: K
) -> Listener
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.