Creates a new reactive value that produces events from this
reactive value
only after that
produces an event.
Creates a new reactive value that produces events from this
reactive value
only after that
produces an event.
After that
emits some event, all events from this
are produced on the resulting reactive.
If that
unreacts before an event is produced on this
, the resulting reactive unreacts.
If this
unreacts, the resulting reactive unreacts.
the type of that
reactive
the reactive after whose first event the result can start propagating events
a subscription and the resulting reactive that emits only after that
emits
at least once.
Returns the last event produced by this
signal.
A signal that only emits events when the value of this
signal changes.
A signal that only emits events when the value of this
signal changes.
time ---------------> this --1---2--2--3--> changes --1---2-----3-->
a subscription and the signal with changes of this
Filters events from this
reactive and maps them in the same time.
Filters events from this
reactive and maps them in the same time.
The collect
combinator uses a partial function pf
to filter events
from this
reactive. Events for which the partial function is defined
are mapped using the partial function, others are discarded.
Note:
This combinator is defined only for reactives that contain reference events.
You cannot call it for reactives whose events are primitive values, such as Int
.
This is because the PartialFunction
class is not specialized.
the type of the mapped reactive
partial function used to filter and map events
evidence that T
is a reference type
a subscription and a reactive value with the partially mapped events
A signal that produces difference events between the current and previous value of this
signal.
A signal that produces difference events between the current and previous value of this
signal.
time ----------------> this --1--3---6---7--> diff --z--2---3---1-->
the type of the difference event
the initial value for the difference
the operator that computes the difference between consecutive events
a subscription and a signal with the difference value
Filters events from this
reactive value using a specified predicate p
.
Filters events from this
reactive value using a specified predicate p
.
Only events from this
for which p
returns true
are emitted on the resulting reactive.
the predicate used to filter events
a subscription and a reactive with the filtered events
Executes the specified function every time an event arrives.
Executes the specified function every time an event arrives.
Semantically equivalent to onEvent
,
but supports for
-loop syntax with reactive values.
for (event <- r) println("Event arrived: " + event)
the callback invoked when an event arrives
a subscription that is also a reactive value
producing Unit
events after each callback invocation
Is there any other reactive that depends on the events produced by this reactive.
Is there any other reactive that depends on the events produced by this reactive.
Passive reactives, such as Reactive.items
will always returns false
.
Other reactives will return true
if there are any subscribers attached to them.
This method is used internally to optimize and recycle some subscriptions away.
Checks if this reactive value is also a signal.
Checks if this reactive value is also a signal.
true
if the reactive value is a signal, false
otherwise
Maps the signal using the specified mapping function f
.
Mutates multiple reactive mutables m1
, m2
and mr
each time
this
reactive value produces an event.
Mutates multiple reactive mutables m1
, m2
and mr
each time
this
reactive value produces an event.
This version of the mutate
works on multiple reactive values.
the type of the reactive mutable value
the first mutable
the second mutable
the rest of the mutables
the function that modifies the mutables
a subscription used to cancel this mutation
Mutates the target reactive mutable called mutable
each time this
reactive value produces an event.
Mutates the target reactive mutable called mutable
each time this
reactive value produces an event.
One type of a reactive mutable is a mutable signal (Signal.Mutable
),
which is a wrapper for regular mutable objects.
Here is an example, given a reactive of type r
:
val eventLog = Signal.Mutable(mutable.Buffer[String]()) val eventLogMutations = r.mutate(eventLog) { event => eventLog() += "at " + System.nanoTime + ": " + event } // <-- eventLog event propagated
Whenever an event arrives on r
, an entry is added to the buffer underlying eventLog
.
After the mutation
completes, a modification event is produced by the eventLog
and can be used subsequently:
val uiUpdates = eventLog onEvent { b => eventListWidget.add(b.last) }
Use case:
def mutate(mutable: ReactMutable)(mutation: T => Unit): Reactive.Subscription
the type of the reactive mutable value
the target mutable to be mutated with events from this stream
the function that modifies mutable
given an event of type T
a subscription used to cancel this mutation
No two events will ever be concurrently processed by different threads on the same reactive mutable,
but an event that is propagated from within the mutation
can trigger an event on this
.
The result is that mutation
is invoked concurrently on the same thread.
The following code is problematic has a feedback loop in the dataflow graph:
val emitter = new Reactive.Emitter[Int] val cell = ReactCell(0) // type of ReactMutable emitter.mutate(cell) { n => cell := n if (n == 0) emitter += n + 1 // <-- event propagated assert(cell() == n) } emitter += 0
The statement emitter += n + 1
in the mutate
block
suspends the current mutation, calls the mutation
recursively and changes the value of cell
, and the assertion fails when
the first mutation resumes.
Care must be taken to avoid mutation
from emitting events that have feedback loops.
Returns events from the last reactive value that this
emitted as an event of its own,
in effect multiplexing the nested reactives.
Returns events from the last reactive value that this
emitted as an event of its own,
in effect multiplexing the nested reactives.
The resulting reactive only emits events from the reactive value last emitted by this
,
the preceding reactive values are ignored.
This combinator is only available if this reactive value emits events that are themselves reactive values.
Example:
val currentReactive = new Reactive.Emitter[Reactive[Int]] val e1 = new Reactive.Emitter[Int] val e2 = new Reactive.Emitter[Int] val currentEvent = currentReactive.mux() val prints = currentEvent.onEvent(println) currentReactive += e1 e2 += 1 // nothing is printed e1 += 2 // 2 is printed currentReactive += e2 e2 += 6 // 6 is printed e1 += 7 // nothing is printed
Shown on the diagram:
time -------------------> currentReactive --e1------e2-------> e1 --------2----6-----> e2 -----1----------7--> currentEvent --------2----6----->
Use case:
def mux[S](): Reactive[S]
the type of the events in the nested reactive
an implicit evidence that this
reactive is nested --
it emits events of type T
that is actually a Reactive[S]
a reactive of events from the reactive last emitted by this
Creates a signal that uses the current signal nested in this
signal to compute the resulting value,
in effect multiplexing the nested signals.
Creates a signal that uses the current signal nested in this
signal to compute the resulting value,
in effect multiplexing the nested signals.
Whenever the nested signal changes, or the value of the nested signal changes, an event with the current nested signal value is emitted and stored as the value of the resulting signal.
Unreacts when both this
and the last nested signal unreact.
time --------------------------------> this 1--2--3----4--5--6--------------> 0--0--0-----0---0--0---> 1--2---4--8--> muxSignal 1--2--3--0--0--0---1--2---4--8-->
This is similar to mux
, but emits the initial value of the signal as an event too --
this is because mux
does not require the nested reactive to be a signal.
Use case:
def muxSignal[S](): Signal[S]
type of the nested signal
evidence that the type of this
signal T
is a signal of type S
a subscription and a signal with the multiplexed values.
A shorthand for onReaction
-- called whenever an event occurs.
A shorthand for onReaction
-- called whenever an event occurs.
This method is handy when the precise event is not important,
or the type of the event is Unit
.
the callback invoked when an event arrives
a subscription for unsubscribing from reactions
A shorthand for onReaction
-- the specified partial function is applied to only those events
for which is defined.
A shorthand for onReaction
-- the specified partial function is applied to only those events
for which is defined.
This method only works for AnyRef
values.
Example:
r onCase { case s: String => println(s) case n: Int => println("number " + s) }
Use case:
def onCase(reactor: PartialFunction[T, Unit]): Reactive.Subscription
the callback for those events for which it is defined
a subscription for unsubscribing from reactions
A shorthand for onReaction
-- the specified function is invoked whenever there is an event.
A shorthand for onReaction
-- the specified function is invoked whenever there is an event.
the callback for events
a subcriptions for unsubscribing from reactions
Attaches a new reactor
to this reactive
that is called multiple times when an event is produced
and once when the reactive is terminated.
Attaches a new reactor
to this reactive
that is called multiple times when an event is produced
and once when the reactive is terminated.
Reactives can create events specifically for this reactor, in which case they are called passive. A passive reactive can create events both synchronously and asynchronously, but it will only do so on its own isolate.
An active reactive value will produce events irregardless of the reactors subscribed to it. Subscribing to an active reactive value only forwards those events that have been produced after the subscription started.
the reactor that accepts react
and unreact
events
a subscription for unsubscribing from reactions
Executes the specified block when this
reactive unreacts.
Executes the specified block when this
reactive unreacts.
a subscription for the unreaction notification
A renewed instance of this signal emitting the same events, but having a different set of subscribers.
A renewed instance of this signal emitting the same events, but having a different set of subscribers.
time -------------> this --1----2--3--> renewed --1----2--3-->
a subscription and a new instance of this
signal
Creates a new reactive s
that produces events by consecutively
applying the specified operator op
to the previous event that s
produced and the current event that this reactive value produced.
Creates a new reactive s
that produces events by consecutively
applying the specified operator op
to the previous event that s
produced and the current event that this reactive value produced.
The scanPast
operation allows the current event from this reactive to be mapped into a different
event by looking "into the past", i.e. at the event previously emitted by the resulting reactive.
Example -- assume that a reactive value r
produces events 1
, 2
and 3
.
The following s
:
val s = r.scanPast(0)((sum, n) => sum + n)
will produce events 1
, 3
(1 + 2
) and 6
(3 + 3
).
Note: the initial value 0
is not emitted.
The scanPast
can also be used to produce a reactive value of a different type:
The following produces a complete history of all the events seen so far:
val s2 = r.scanPast(List[Int]()) { (history, n) => n :: history }
The s2
will produce events 1 :: Nil
, 2 :: 1 :: Nil
and 3 :: 2 :: 1 :: Nil
.
Note: the initial value Nil
is not emitted.
The resulting reactive value is not only a reactive value, but also a Signal
,
so the value of the previous event can be obtained by calling apply
at any time.
This operation is closely related to a scanLeft
on a collection --
if a reactive value were a sequence of elements, then scanLeft
would produce
a new sequence whose elements correspond to the events of the resulting reactive.
the type of the events in the resulting reactive value
the initial value of the scan past
the operator the combines the last produced and the current event into a new one
a subscription that is also a reactive value that scans events from this
reactive value
Creates a new reactive value that produces events from this
reactive value
until that
produces an event.
Creates a new reactive value that produces events from this
reactive value
until that
produces an event.
If this
unreacts before that
produces a value, the resulting reactive unreacts.
Otherwise, the resulting reactive unreacts whenever that
produces a value.
the type of that
reactive
the reactive until whose first event the result propagates events
a subscription and the resulting reactive that emits only until that
emits
Zips values of this
and that
signal using the specified function f
.
Zips values of this
and that
signal using the specified function f
.
Whenever either of the two signals change the resulting signal also changes.
When this
emits an event, the current value of that
is used to produce a signal on that
,
and vice versa.
time ---------------------------------> this --1----2-----4----------8--------> that --a----------------b---------c---> zip --1,a--2,a---4,a---4,b--8,b--8,c->
The resulting tuple of events from this
and that
is mapped using the
user-specified mapping function f
.
For example, to produce tuples:
val tuples = (a zip b) { (a, b) => (a, b) }
To produce the difference between two integer signals:
val differences = (a zip b)(_ - _)
Note:: clients looking into pairing incoming events from two signals
you should use the sync
method inherited from Reactive
.
the type of that
signal
the type of the resulting signal
the signal to zip this
with
the function that maps a tuple of values into an outgoing event
a subscription and the reactive that emits zipped events
Downcasts this reactive into a signal.
Downcasts this reactive into a signal.
Throws an exception if the current reactive is not a signal.
the signal version of the current reactive
(entry: ReactiveOps[V]).asSignal
Downcasts this reactive into a signal.
Downcasts this reactive into a signal.
Throws an exception if the current reactive is not a signal.
the signal version of the current reactive
(entry: ReactiveOps[V]).asSignal
If the current reactive is a signal already this method downcasts it,
otherwise it lifts it into a signal with the initial value init
.
If the current reactive is a signal already this method downcasts it,
otherwise it lifts it into a signal with the initial value init
.
optional value to use when converting the reactive to a signal
the signal version of the current reactive
(entry: ReactiveOps[V]).asSignalOrElse(init)
If the current reactive is a signal already this method downcasts it,
otherwise it lifts it into a signal with the initial value init
.
If the current reactive is a signal already this method downcasts it,
otherwise it lifts it into a signal with the initial value init
.
optional value to use when converting the reactive to a signal
the signal version of the current reactive
(entry: ReactiveOps[V]).asSignalOrElse(init)
Concatenates the events produced by all the reactives emitted by this
.
Concatenates the events produced by all the reactives emitted by this
.
This operation is only available for reactive values that emit
other reactives as events.
Once this
and all the reactives unreact, this reactive unreacts.
Use case:
def concat[S](): Reactive[S]
the type of the events in reactives emitted by this
evidence that events of type T
produced by this
are
actually reactive values of type S
evidence that arrays can be created for type S
evidence that buffering events is allowed
a subscription and the reactive that concatenates all the events
(entry: ReactiveOps[V]).concat()(evidence, a, b)
This operation potentially buffers events from the nested reactives.
Unless each reactive emitted by this
is known to unreact eventually,
this operation should not be called.
To enforce this, clients are required to import the CanBeBuffered
evidence
explicitly into the scope in which they call concat
.
Creates a concatenation of this
and that
reactive.
Creates a concatenation of this
and that
reactive.
The resulting reactive value produces all the events from this
reactive
until this
unreacts, and then outputs all the events from that
that happened before and after this
unreacted.
To do this, this operation potentially caches all the events from that
.
When that
unreacts, the resulting reactive value unreacts.
Use case:
def concat(that: Reactive[T]): Reactive[T]
another reactive value for the concatenation
evidence that arrays can be created for the type T
evidence that the client allows events from that
to be buffered
a subscription and a reactive value that concatenates events from this
and that
(entry: ReactiveOps[V]).concat(that)(a, b)
This operation potentially caches events from that
.
Unless certain that this
eventually unreacts, concat
should not be used.
To enforce this, clients must import the CanBeBuffered
evidence explicitly
into the scope in which they call concat
.
Concatenates the events produced by all the reactives emitted by this
.
Concatenates the events produced by all the reactives emitted by this
.
This operation is only available for reactive values that emit
other reactives as events.
Once this
and all the reactives unreact, this reactive unreacts.
Use case:
def concat[S](): Reactive[S]
the type of the events in reactives emitted by this
evidence that events of type T
produced by this
are
actually reactive values of type S
evidence that arrays can be created for type S
evidence that buffering events is allowed
a subscription and the reactive that concatenates all the events
(entry: ReactiveOps[V]).concat()(evidence, a, b)
This operation potentially buffers events from the nested reactives.
Unless each reactive emitted by this
is known to unreact eventually,
this operation should not be called.
To enforce this, clients are required to import the CanBeBuffered
evidence
explicitly into the scope in which they call concat
.
Creates a concatenation of this
and that
reactive.
Creates a concatenation of this
and that
reactive.
The resulting reactive value produces all the events from this
reactive
until this
unreacts, and then outputs all the events from that
that happened before and after this
unreacted.
To do this, this operation potentially caches all the events from that
.
When that
unreacts, the resulting reactive value unreacts.
Use case:
def concat(that: Reactive[T]): Reactive[T]
another reactive value for the concatenation
evidence that arrays can be created for the type T
evidence that the client allows events from that
to be buffered
a subscription and a reactive value that concatenates events from this
and that
(entry: ReactiveOps[V]).concat(that)(a, b)
This operation potentially caches events from that
.
Unless certain that this
eventually unreacts, concat
should not be used.
To enforce this, clients must import the CanBeBuffered
evidence explicitly
into the scope in which they call concat
.
Creates a new signal that emits tuples of the current
and the last event emitted by this
signal.
Creates a new signal that emits tuples of the current
and the last event emitted by this
signal.
time ----------------------> this 1----2------3----4----> past2 i,1--1,2----2,3--3,4-->
the initial previous value, i
in the diagram above
a subscription and a signal of tuples of the current and last event
(entry: SignalOps[V]).past2(init)
Creates a new signal that emits tuples of the current
and the last event emitted by this
signal.
Creates a new signal that emits tuples of the current
and the last event emitted by this
signal.
time ----------------------> this 1----2------3----4----> past2 i,1--1,2----2,3--3,4-->
the initial previous value, i
in the diagram above
a subscription and a signal of tuples of the current and last event
(entry: SignalOps[V]).past2(init)
Scans the events in the past of this
signal starting from the
current value of this
signal.
Scans the events in the past of this
signal starting from the
current value of this
signal.
time --------------------> this 1--2----4-----8-----> scanPastNow 1--3----7-----15---->
(entry: SignalOps[V]).scanPastNow(op)
Scans the events in the past of this
signal starting from the
current value of this
signal.
Scans the events in the past of this
signal starting from the
current value of this
signal.
time --------------------> this 1--2----4-----8-----> scanPastNow 1--3----7-----15---->
(entry: SignalOps[V]).scanPastNow(op)
(entry: ReactiveOps[V]).self
(entry: SignalOps[V]).self
(entry: ReactiveOps[V]).self
(entry: SignalOps[V]).self
(entry: StringAdd).self
(entry: StringFormat).self
Given an initial event init
, converts this reactive into a Signal
.
Given an initial event init
, converts this reactive into a Signal
.
The resulting signal initially contains the event init
,
and subsequently any event that the this
reactive produces.
an initial value for the signal
the signal version of the current reactive
(entry: ReactiveOps[V]).signal(init)
Given an initial event init
, converts this reactive into a Signal
.
Given an initial event init
, converts this reactive into a Signal
.
The resulting signal initially contains the event init
,
and subsequently any event that the this
reactive produces.
an initial value for the signal
the signal version of the current reactive
(entry: ReactiveOps[V]).signal(init)
Syncs the arrival of events from this
and that
reactive value.
Syncs the arrival of events from this
and that
reactive value.
Ensures that pairs of events from this reactive value and that reactive value
are emitted together.
If the events produced in time by this
and that
, the sync will be as follows:
time ---------------------------> this ----1---------2-------4----> that --1-----2--3---------------> sync ----1,1-------2,2-----4,3-->
Pairs of events produced from this
and that
are then transformed using
specified function f
.
For example, clients that want to output tuples do:
val synced = (a sync b) { (a, b) => (a, b) }
Clients that, for example, want to create differences in pairs of events do:
val diffs = (a sync b)(_ - _)
The resulting reactive unreacts either when
this
unreacts and there are no more buffered events from this,
or when that
unreacts and there are no more buffered events from that
.
Use case:
def sync[S, R](that: Reactive[S])(f: (T, S) => R): Reactive[R]
the type of the events in that
reactive
the type of the events in the resulting reactive
the reactive to sync with
the mapping function for the pair of events
evidence that arrays can be created for the type T
evidence that arrays can be created for the type S
evidence that the client allows events to be buffered
a subscription and the reactive with the resulting events
(entry: ReactiveOps[V]).sync(that)(f)(at, as, b)
This operation potentially caches events from this
and that
.
Unless certain that both this
produces a bounded number of events
before the that
produces an event, and vice versa, this operation should not be called.
To enforce this, clients must import the CanBeBuffered
evidence explicitly
into the scope in which they call sync
.
Syncs the arrival of events from this
and that
reactive value.
Syncs the arrival of events from this
and that
reactive value.
Ensures that pairs of events from this reactive value and that reactive value
are emitted together.
If the events produced in time by this
and that
, the sync will be as follows:
time ---------------------------> this ----1---------2-------4----> that --1-----2--3---------------> sync ----1,1-------2,2-----4,3-->
Pairs of events produced from this
and that
are then transformed using
specified function f
.
For example, clients that want to output tuples do:
val synced = (a sync b) { (a, b) => (a, b) }
Clients that, for example, want to create differences in pairs of events do:
val diffs = (a sync b)(_ - _)
The resulting reactive unreacts either when
this
unreacts and there are no more buffered events from this,
or when that
unreacts and there are no more buffered events from that
.
Use case:
def sync[S, R](that: Reactive[S])(f: (T, S) => R): Reactive[R]
the type of the events in that
reactive
the type of the events in the resulting reactive
the reactive to sync with
the mapping function for the pair of events
evidence that arrays can be created for the type T
evidence that arrays can be created for the type S
evidence that the client allows events to be buffered
a subscription and the reactive with the resulting events
(entry: ReactiveOps[V]).sync(that)(f)(at, as, b)
This operation potentially caches events from this
and that
.
Unless certain that both this
produces a bounded number of events
before the that
produces an event, and vice versa, this operation should not be called.
To enforce this, clients must import the CanBeBuffered
evidence explicitly
into the scope in which they call sync
.
Unifies the events produced by all the reactives emitted by this
.
Unifies the events produced by all the reactives emitted by this
.
This operation is only available for reactive values that emit
other reactives as events.
The resulting reactive unifies events of all the reactives emitted by this
.
Once this
and all the reactives emitted by this
unreact, the resulting reactive terminates.
Example:
time --------------------------> this --1----2--------3------> ---------5----6----> ---4----------7--> union -----1----2-4---5--3-6-7-->
Use case:
def union[S](): Reactive[S]
the type of the events in reactives emitted by this
evidence that events of type T
produced by this
are
actually reactive values of type S
a subscription and the reactive with the union of all the events
(entry: ReactiveOps[V]).union()(evidence)
Creates a union of this
and that
reactive.
Creates a union of this
and that
reactive.
The resulting reactive value emits events from both this
and that
reactive.
It unreacts when both this
and that
reactive unreact.
another reactive value for the union
a subscription and the reactive value with unified events from this
and that
(entry: ReactiveOps[V]).union(that)
Unifies the events produced by all the reactives emitted by this
.
Unifies the events produced by all the reactives emitted by this
.
This operation is only available for reactive values that emit
other reactives as events.
The resulting reactive unifies events of all the reactives emitted by this
.
Once this
and all the reactives emitted by this
unreact, the resulting reactive terminates.
Example:
time --------------------------> this --1----2--------3------> ---------5----6----> ---4----------7--> union -----1----2-4---5--3-6-7-->
Use case:
def union[S](): Reactive[S]
the type of the events in reactives emitted by this
evidence that events of type T
produced by this
are
actually reactive values of type S
a subscription and the reactive with the union of all the events
(entry: ReactiveOps[V]).union()(evidence)
Creates a union of this
and that
reactive.
Creates a union of this
and that
reactive.
The resulting reactive value emits events from both this
and that
reactive.
It unreacts when both this
and that
reactive unreact.
another reactive value for the union
a subscription and the reactive value with unified events from this
and that
(entry: ReactiveOps[V]).union(that)
(entry: ArrowAssoc[Entry[K, V]]).x
(Since version 2.10.0) Use leftOfArrow
instead
(entry: Ensuring[Entry[K, V]]).x
(Since version 2.10.0) Use resultOfEnsuring
instead