Signal with a constant value.
Signal containing a mutable value.
Signal containing a mutable value.
Value can be accessed with the apply
method.
To modify the content, clients must use the mutate
method on event streams.
A signal that is the aggregation of the values of other signals
.
A signal that is the aggregation of the values of other signals
.
At any point during execution this signal will contain
an event obtained by applying op
on the values of all
the events in signals
.
This signal aggregate is called a static aggregate
since the signals
set is specified during aggregate
creation and cannot be changed afterwards.
The signal aggregate creates an aggregation tree data structure,
so a value update in one of the signals
requires only O(log n)
steps to update the value of the aggregate signal.
Example:
val emitters = for (0 until 10) yield new Events.Emitter[Int] val ag = Signal.aggregate(emitters)(_ + _)
The aggregation operator needs to be associative, but does not need to be commutative. For example, string concatenation for signals of strings or addition for integer signals are valid operators. Subtraction for integer signals, for example, is not associative and not allowed.
The value z
for the aggregation does not need to be a neutral element with
respect to the aggregation operation.
The resulting signal is hot, i.e. its value is updated even if there are no subscribers.
type of the aggregate signal
signals for the aggregation
the zero value of the aggregation, used if the list is empty
the aggregation operator, must be associative
Zips the list of signals, and produces an output signal from their values.
Zips the list of signals, and produces an output signal from their values.
The output signal is updated whenever any of the input signals are updated.
The value used for the output is given by the specified update function f
.
Assume that the update function returns the first uppercase character, or ?
if
there are no uppercase characters:
Signal.zip(sig1, sig2, sig3) { ss => () => ss.find(s => s().isUpper).map(_()).getOrElse('?')) }
The values are produced as follows:
time -----------------------------> sig1 d------------g--B------h-----> sig2 c----f-----------------------> sig3 e---------A------------------> output ?----?----A--A--B------A----->
Above, the output returns ?
each time any of the inputs is updated, until the
signal-3
becomes A
-- at this point, the output value changes to A
. The
output value is still A
when signal-1
produces g
, as the current values
of the signals are (g, f, A)
at this point. When signal-1
becomes B
,
the values of all the signals are (B, f, A)
, so the output becomes B
,
and so on.
Note: traversing all of the signals in the specified function in order to
update the value of the resulting signal takes O(n)
time, where n
is the
number of signals specified, and can be potentially slow. If the update function
is associative (e.g., adding integers of the input signals), then the output
signal can be computed incrementally, and Signal.aggregate
should be used
instead.
type of the input signals
type of the output signal
list of input signals
function used to produce the output from the input signals
the output signal