pub struct Cell<A> {
pub impl_: Cell<A>,
}Expand description
Represents a value of type A that changes over time.
In other Functional Reactive Programming (FRP) systems this is
also called a behavior, property, or a signal. A Cell
should be used for modeling any pieces of mutable state in an FRP
application.
Fields§
§impl_: Cell<A>Implementations§
Source§impl<A: Clone + Send + 'static> Cell<A>
impl<A: Clone + Send + 'static> Cell<A>
Sourcepub fn sample(&self) -> A
pub fn sample(&self) -> A
Sample the Cell’s current value.
Cell::sample may be used in the functions passed to
primitives that apply them to Streams, including
Stream::map, Stream::snapshot, Stream::filter, and
Stream::merge.
When called within a function passed to Stream::map using
sample is equivalent to snapshotting
this Cell with that Stream.
Sourcepub fn sample_lazy(&self) -> Lazy<A>
pub fn sample_lazy(&self) -> Lazy<A>
Sample the Cell’s current value lazily.
When it is necessary to use sample while implementing more
general abstractions, sample_lazy should be preferred in
case a CellLoop is passed rather than a
Cell.
See Cell::sample for more details.
Sourcepub fn updates(&self) -> Stream<A>
pub fn updates(&self) -> Stream<A>
Return a Stream that gives the updates/steps for a Cell.
§Important
This is an operational primitive, which isn’t part of the main
Sodium API. It breaks the property of non-detectability of
cell updates/steps. The rule with this primitive is that you
should only use it in functions that don’t allow the caller to
detect the Cell updates.
Sourcepub fn value(&self) -> Stream<A>
pub fn value(&self) -> Stream<A>
Return a Stream that is guaranteed to fire at least once.
When value is called, the returned Stream will fire once
in the current transaction with the current value of this
Cell and thereafter behaves like Cell::updates.
§Important
This is an operational primitive, which isn’t part of the main
Sodium API. It breaks the property of non-detectability of
cell updates/steps. The rule with this primitive is that you
should only use it in functions that don’t allow the caller to
detect the Cell updates.
Sourcepub fn map<B: Clone + Send + 'static, FN: IsLambda1<A, B> + Send + Sync + 'static>(
&self,
f: FN,
) -> Cell<B>
pub fn map<B: Clone + Send + 'static, FN: IsLambda1<A, B> + Send + Sync + 'static>( &self, f: FN, ) -> Cell<B>
Transform the Cells value with the supplied function.
The returned Cell always reflects the value produced by the
function applied to the input Cells value. The given
function must be referentially transparent.
Sourcepub fn lift2<B: Clone + Send + 'static, C: Clone + Send + 'static, FN: IsLambda2<A, B, C> + Send + 'static>(
&self,
cb: &Cell<B>,
f: FN,
) -> Cell<C>
pub fn lift2<B: Clone + Send + 'static, C: Clone + Send + 'static, FN: IsLambda2<A, B, C> + Send + 'static>( &self, cb: &Cell<B>, f: FN, ) -> Cell<C>
Lift a binary function into cells so the returned Cell
always reflects the specified function applied to the input
cells’ values.
Sourcepub fn lift3<B: Clone + Send + 'static, C: Clone + Send + 'static, D: Clone + Send + 'static, FN: IsLambda3<A, B, C, D> + Send + 'static>(
&self,
cb: &Cell<B>,
cc: &Cell<C>,
f: FN,
) -> Cell<D>
pub fn lift3<B: Clone + Send + 'static, C: Clone + Send + 'static, D: Clone + Send + 'static, FN: IsLambda3<A, B, C, D> + Send + 'static>( &self, cb: &Cell<B>, cc: &Cell<C>, f: FN, ) -> Cell<D>
Lift a ternary function into cells so the returned Cell
always reflects the specified function applied to the input
cells’ values.
Sourcepub fn lift4<B: Clone + Send + 'static, C: Clone + Send + 'static, D: Clone + Send + 'static, E: Clone + Send + 'static, FN: IsLambda4<A, B, C, D, E> + Send + 'static>(
&self,
cb: &Cell<B>,
cc: &Cell<C>,
cd: &Cell<D>,
f: FN,
) -> Cell<E>
pub fn lift4<B: Clone + Send + 'static, C: Clone + Send + 'static, D: Clone + Send + 'static, E: Clone + Send + 'static, FN: IsLambda4<A, B, C, D, E> + Send + 'static>( &self, cb: &Cell<B>, cc: &Cell<C>, cd: &Cell<D>, f: FN, ) -> Cell<E>
Lift a quaternary function into cells so the returned Cell
always reflects the specified function applied to the input
cells’ values.
Sourcepub fn lift5<B: Clone + Send + 'static, C: Clone + Send + 'static, D: Clone + Send + 'static, E: Clone + Send + 'static, F: Clone + Send + 'static, FN: IsLambda5<A, B, C, D, E, F> + Send + 'static>(
&self,
cb: &Cell<B>,
cc: &Cell<C>,
cd: &Cell<D>,
ce: &Cell<E>,
f: FN,
) -> Cell<F>
pub fn lift5<B: Clone + Send + 'static, C: Clone + Send + 'static, D: Clone + Send + 'static, E: Clone + Send + 'static, F: Clone + Send + 'static, FN: IsLambda5<A, B, C, D, E, F> + Send + 'static>( &self, cb: &Cell<B>, cc: &Cell<C>, cd: &Cell<D>, ce: &Cell<E>, f: FN, ) -> Cell<F>
Lift a five-argument function into cells so the returned
Cell always reflects the specified function applied to the
input cells’ values.
Sourcepub fn lift6<B: Clone + Send + 'static, C: Clone + Send + 'static, D: Clone + Send + 'static, E: Clone + Send + 'static, F: Clone + Send + 'static, G: Clone + Send + 'static, FN: IsLambda6<A, B, C, D, E, F, G> + Send + 'static>(
&self,
cb: &Cell<B>,
cc: &Cell<C>,
cd: &Cell<D>,
ce: &Cell<E>,
cf: &Cell<F>,
f: FN,
) -> Cell<G>
pub fn lift6<B: Clone + Send + 'static, C: Clone + Send + 'static, D: Clone + Send + 'static, E: Clone + Send + 'static, F: Clone + Send + 'static, G: Clone + Send + 'static, FN: IsLambda6<A, B, C, D, E, F, G> + Send + 'static>( &self, cb: &Cell<B>, cc: &Cell<C>, cd: &Cell<D>, ce: &Cell<E>, cf: &Cell<F>, f: FN, ) -> Cell<G>
Lift a six argument function into cells so the returned
Cell always reflects the specified function applied to the
input cells’ values.
Sourcepub fn switch_s(csa: &Cell<Stream<A>>) -> Stream<A>
pub fn switch_s(csa: &Cell<Stream<A>>) -> Stream<A>
Unwrap a Stream in a Cell to give a time-varying stream implementation.
Sourcepub fn switch_c(cca: &Cell<Cell<A>>) -> Cell<A>
pub fn switch_c(cca: &Cell<Cell<A>>) -> Cell<A>
Unwrap a Cell in another Cell to give a time-varying cell implementation.
Sourcepub fn listen_weak<K: FnMut(&A) + Send + Sync + 'static>(
&self,
k: K,
) -> Listener
pub fn listen_weak<K: FnMut(&A) + Send + Sync + 'static>( &self, k: K, ) -> Listener
A variant of listen that will deregister the
listener automatically if the listener is garbage-collected.