Signal

object Signal
Companion
class
class Object
trait Matchable
class Any

Value members

Concrete methods

def and(sources: Signal[Boolean]*): Signal[Boolean]

Creates a Signal[Boolean] of an arbitrary number of parent signals of Boolean. The new signal's value will be true only if all parent signals values are true, and false if even one of them changes its value to false.

Creates a Signal[Boolean] of an arbitrary number of parent signals of Boolean. The new signal's value will be true only if all parent signals values are true, and false if even one of them changes its value to false.

Value Params
sources

A variable arguments list of parent signals of the type Boolean.

Returns

A new signal of Boolean.

def apply[V](): SourceSignal[V]

Creates a new SourceSignal of values of the type V. A usual entry point for the signals network. Starts uninitialized (its value is set to None).

Creates a new SourceSignal of values of the type V. A usual entry point for the signals network. Starts uninitialized (its value is set to None).

Type Params
V

The type of the values which can be published to the signal.

Returns

A new signal of values of the type V.

def apply[V](v: V): SourceSignal[V]

Creates a new SourceSignal of values of the type V. A usual entry point for the signals network. Starts initialized to the given value.

Creates a new SourceSignal of values of the type V. A usual entry point for the signals network. Starts initialized to the given value.

Type Params
V

The type of the values which can be published to the signal.

Value Params
v

The initial value in the signal.

Returns

A new signal of values of the type V.

def const[V](v: V): Signal[V]

Creates a ConstSignal initialized to the given value. Use a const signal for providing a source of an immutable value in the chain of signals. Subscribing to a const signal usually makes no sense, but they can be used in flatMaps in cases where the given value of the parent signal should result always in the same value. Using ConstSignal in such case should have some performance advantage over using a regular signal holding a (in theory mutable) value.

Creates a ConstSignal initialized to the given value. Use a const signal for providing a source of an immutable value in the chain of signals. Subscribing to a const signal usually makes no sense, but they can be used in flatMaps in cases where the given value of the parent signal should result always in the same value. Using ConstSignal in such case should have some performance advantage over using a regular signal holding a (in theory mutable) value.

Type Params
V

The type of the value.

Value Params
v

The immutable value held by the signal.

Returns

A new const signal initialized to the given value.

See also
def either[L, R](left: Signal[L], right: Signal[R]): Signal[Either[L, R]]

A generalization of the orElse method where the fallback (left) signal can have another value type. If the value of the main (right) signal is R and the value of the fallback (left) signal is L, the new signal will return an Either[L, R]. When the right signal is set, the value of the new signal will be Right(r). When the right signal becomes empty, the value of the new signal will temporarily switch to Left(l) where l is the current value of the left signal. The moment the parent signal is set to a new value again, the new signal will switch back to Right(r). Only when both signals are empty, the new signal will become empty too.

A generalization of the orElse method where the fallback (left) signal can have another value type. If the value of the main (right) signal is R and the value of the fallback (left) signal is L, the new signal will return an Either[L, R]. When the right signal is set, the value of the new signal will be Right(r). When the right signal becomes empty, the value of the new signal will temporarily switch to Left(l) where l is the current value of the left signal. The moment the parent signal is set to a new value again, the new signal will switch back to Right(r). Only when both signals are empty, the new signal will become empty too.

Type Params
L

The value type of the fallback (left) signal.

R

The value type of the main (right) signal.

Value Params
left

The signal providing the left value for the resulting signal. It works as a fallback if the right one is empty.

right

The signal providing the right value. This is the main signal. It has a priority over left.

Returns

A new signal with the value being either the value of the main or the value of the fallback signal if the main is empty.

@inline
def empty[V]: Signal[V]

Returns an empty, uninitialized, immutable signal of the given type. Empty signals can be used in flatMap chains to signalize (ha!) that for the given value of the parent signal all further computations should be withheld until the value changes to something more useful.

Returns an empty, uninitialized, immutable signal of the given type. Empty signals can be used in flatMap chains to signalize (ha!) that for the given value of the parent signal all further computations should be withheld until the value changes to something more useful.

val parentSignal = Signal[Int]()
val thisSignal = parentSignal.flatMap {
 case n if n > 2 => Signal.const(n * 2)
 case _ => Signal.empty[Int]
}
thisSignal.foreach(println)

Here, the function println will be called only for values > 2 published to parentSignal. Basically, you may think of empty signals as a way to build alternatives to Signal.filter and Signal.collect when you need more fine-grained control over conditions of propagating values.

Type Params
V

The type of the value (used only in type-checking)

Returns

A new empty signal.

See also
def foldLeft[V, Z](sources: Signal[V]*)(zero: Z)(f: (Z, V) => Z): Signal[Z]

Creates a signal from an initial value, a list of parent signals, and a folding function. On initialization, and then on every change of value of any of the parent signals, the folding function will be called for the whole list and use the current values to produce a result, analogous to the foldLeft method in Scala collections.

Creates a signal from an initial value, a list of parent signals, and a folding function. On initialization, and then on every change of value of any of the parent signals, the folding function will be called for the whole list and use the current values to produce a result, analogous to the foldLeft method in Scala collections.

Type Params
V

The type of values in the parent streams.

Z

The type of the initial and result value of the new signal.

Value Params
f

A folding function which takes the value of the type Z, another value of the type V, and produces a new value of the type Z again, so then it can use it in the next interation as its first argument, together with the current value of the next of the parent signals.

sources

A variable arguments list of parent signals, all with values of the same type V.

zero

The initial value of the type Z.

Returns

A new signal of values of the type Z.

@inline
def from[V](future: Future[V], executionContext: ExecutionContext): Signal[V]

Creates a new signal from a future. The signal will start uninitialized and initialize to its only, never again changing value if the future finishes with success. If the future fails, the signal will stay empty. The subscriber functions registered in this signal will be called in the given execution context if they don't explicitly specify the execution context they should be called in.

Creates a new signal from a future. The signal will start uninitialized and initialize to its only, never again changing value if the future finishes with success. If the future fails, the signal will stay empty. The subscriber functions registered in this signal will be called in the given execution context if they don't explicitly specify the execution context they should be called in.

Please note that in the typical case the subscriber functions probably will have it specified in what execution context they should be called, as this allows for better control about what code is called in what e.c. The e.c. specified here does not take precedent over the one specified in the subscription. Therefore, usually, it makes sense to use the overloaded version of this method which uses the default execution context.

Type Params
V

The type of the value produced by the future.

Value Params
executionContext

The execution context in which the subscriber functions will be called if not specified otherwise.

future

The future producing the first and only value for the signal.

Returns

A new signal which will hold the value produced by the future.

See also
@inline
def from[V](future: Future[V]): Signal[V]

A version of from using the default execution context as its second argument.

A version of from using the default execution context as its second argument.

@inline
def from[V](future: CancellableFuture[V], executionContext: ExecutionContext): Signal[V]

A version of from creating a signal from a cancellable future.

A version of from creating a signal from a cancellable future.

@inline
def from[V](future: CancellableFuture[V]): Signal[V]

A version of from creating a signal from a cancellable future, and using the default execution context.

A version of from creating a signal from a cancellable future, and using the default execution context.

@inline
def from[V](initial: V, source: EventStream[V]): Signal[V]

Creates a new signal from an event stream and an initial value. The signal will be initialized to the initial value on its creation, and subscribe to the event stream. Subsequently, it will update the value as new events are published in the parent event stream.

Creates a new signal from an event stream and an initial value. The signal will be initialized to the initial value on its creation, and subscribe to the event stream. Subsequently, it will update the value as new events are published in the parent event stream.

Type Params
V

The type of both the initial value and the events in the parent stream.

Value Params
initial

The initial value of the signal.

source

The parent event stream.

Returns

A new signal with the value of the type V.

@inline
def from[V](source: EventStream[V]): Signal[V]

Creates a new signal from an event stream. The signal will start uninitialized and subscribe to the parent event stream. Subsequently, it will update its value as new events are published in the parent event stream.

Creates a new signal from an event stream. The signal will start uninitialized and subscribe to the parent event stream. Subsequently, it will update its value as new events are published in the parent event stream.

Type Params
V

The type of the events in the parent stream.

Value Params
source

The parent event stream.

Returns

A new signal with the value of the type V.

def or(sources: Signal[Boolean]*): Signal[Boolean]

Creates a Signal[Boolean] of an arbitrary number of parent signals of Boolean. The new signal's value will be true if any of the parent signals values is true, and false only if all one of them change its value to false.

Creates a Signal[Boolean] of an arbitrary number of parent signals of Boolean. The new signal's value will be true if any of the parent signals values is true, and false only if all one of them change its value to false.

Value Params
sources

A variable arguments list of parent signals of the type Boolean.

Returns

A new signal of Boolean.

def sequence[V](sources: Signal[V]*): Signal[Seq[V]]

Creates a signal of an arbitrary number of parent signals of the same value. The value of the new signal is the sequence of values of all parent signals in the same order. You can actually think of it as an analogous method to EventStream.zip.

Creates a signal of an arbitrary number of parent signals of the same value. The value of the new signal is the sequence of values of all parent signals in the same order. You can actually think of it as an analogous method to EventStream.zip.

Type Params
V

The type of the values in the parent signals.

Value Params
sources

A variable arguments list of parent signals of the same type.

Returns

A new signal with its value being a sequence of current values of the parent signals.

def throttled[V](source: Signal[V], delay: FiniteDuration): Signal[V]

A utility method for creating a ThrottledSignal with the value of the given type and updated no more often than once during the given time interval. If changes to the value of the parent signal happen more often, some of them will be ignored.

A utility method for creating a ThrottledSignal with the value of the given type and updated no more often than once during the given time interval. If changes to the value of the parent signal happen more often, some of them will be ignored.

Type Params
V

The type of value in both the parent signal and the new one.

Value Params
delay

The time interval used for throttling.

source

The parent signal providing the original value.

Returns

A new throttled signal of the same value type as the parent.

See also
def zip[A, B](s1: Signal[A], s2: Signal[B]): Signal[(A, B)]

Creates a new signal by joining together the original signals of two different types of values, A and B. The resulting signal will hold a tuple of the original values and update every time one of them changes.

Creates a new signal by joining together the original signals of two different types of values, A and B. The resulting signal will hold a tuple of the original values and update every time one of them changes.

Note this is not a method analogous to EventStream.zip. Here the parent signals can be of different type (EventStream.zip requires all parent streams to be of the same type) but on the other hand we're not able to zip an arbitrary number of signals. Also, the result value is a tuple, not just one event after another.

Please also see Signal.sequence for a method which resembles EventStream.zip in a different way.

Type Params
A

The type of the value of the first of parent signals.

B

The type of the value of the second of parent signals.

Value Params
s1

The first of the parent signals.

s2

The second of the parent signals.

Returns

A new signal its the value constructed as a tuple of values form the parent signals.

def zip[A, B, C](s1: Signal[A], s2: Signal[B], s3: Signal[C]): Signal[(A, B, C)]

A version of the zip method joining three signals of different value types.

A version of the zip method joining three signals of different value types.

def zip[A, B, C, D](s1: Signal[A], s2: Signal[B], s3: Signal[C], s4: Signal[D]): Signal[(A, B, C, D)]

A version of the zip method joining four signals of different value types.

A version of the zip method joining four signals of different value types.

def zip[A, B, C, D, E](s1: Signal[A], s2: Signal[B], s3: Signal[C], s4: Signal[D], s5: Signal[E]): Signal[(A, B, C, D, E)]

A version of the zip method joining five signals of different value types.

A version of the zip method joining five signals of different value types.

def zip[A, B, C, D, E, F](s1: Signal[A], s2: Signal[B], s3: Signal[C], s4: Signal[D], s5: Signal[E], s6: Signal[F]): Signal[(A, B, C, D, E, F)]

A version of the zip method joining six signals of different value types.

A version of the zip method joining six signals of different value types.