GeneratorSignal

io.github.makingthematrix.signals3.generators.GeneratorSignal
See theGeneratorSignal companion object
abstract class GeneratorSignal[V] extends Signal[V], NoAutowiring

A signal capable of generating new values in the given intervals of time. The interval can be given either as scala.concurrent.duration.FiniteDuration or as a function that will return scala.concurrent.duration.FiniteDuration every time it's called.

Type parameters

V

The type of the signal's value.

Value parameters

init

The initial value of the generator signal.

interval

Time to the next event generation (to the first event as well). Might be either a FiniteDuration or a function that returns the number of milliseconds. In the second case, the function will be called on initialization, and then after each generated event.

Attributes

Note

If you use the constant scala.concurrent.duration.FiniteDuration as the interval (not the function), the generator will anyway try to adjust for inevitable delays caused by calling its own code. We can assume that the initialization will cause the first call to be executed with some delay, so the second call will be executed a bit earlier than interval to accommodate that. The next calls should be executed as planned, unless external causes will make another delay, after which the repeat method will again try to adjust by shortening the delay for the consecutive call.

Companion
object
Graph
Supertypes
trait NoAutowiring
class Signal[V]
class Object
trait Matchable
class Any
Known subtypes

Members list

Value members

Inherited methods

final inline def &&[Z](other: Signal[Z])(using V <:< Boolean, Z <:< Boolean): Signal[Boolean]

An alias to and.

An alias to and.

Value parameters

other

The other signal with the value type that can be interpreted as Boolean

Attributes

Returns

A new signal of Boolean.

Inherited from:
Signal
final inline def ===[Z](other: Signal[Z]): Signal[Boolean]

An alias for sameAs

An alias for sameAs

Type parameters

Z

The type of the values of the other signal.

Value parameters

other

The other signal used in comparison

Attributes

Returns

A new boolean signal

Inherited from:
Signal
final inline def ^^[Z](other: Signal[Z])(using V <:< Boolean, Z <:< Boolean): Signal[Boolean]

An alias to xor.

An alias to xor.

Value parameters

other

The other signal with the value type that can be interpreted as Boolean

Attributes

Returns

A new signal of Boolean.

Inherited from:
Signal
final inline def and[Z](other: Signal[Z])(using V <:< Boolean, Z <:< Boolean): Signal[Boolean]

Assuming that both the value of this signal and the value of the other signal can be interpreted as a boolean, this method creates a new signal of type Boolean by applying logical AND.

Assuming that both the value of this signal and the value of the other signal can be interpreted as a boolean, this method creates a new signal of type Boolean by applying logical AND.

Value parameters

other

The other signal with the value type that can be interpreted as Boolean

Attributes

Returns

A new signal of Boolean.

Inherited from:
Signal
final def closeable: CloseableSignal[V]

Creates a closeable wrapper around this signal

Creates a closeable wrapper around this signal

Attributes

Returns

A new closeable signal or this one if it's already closeable

Inherited from:
Signal
final inline def collect[Z](pf: PartialFunction[V, Z]): Signal[Z]

Creates a new signal of values of the type Z by applying a partial function which maps the original value of the type V to a value of the type Z. If the partial function doesn't work for the current value, the new signal will become empty until the next update. Basically, it's filter + map.

Creates a new signal of values of the type Z by applying a partial function which maps the original value of the type V to a value of the type Z. If the partial function doesn't work for the current value, the new signal will become empty until the next update. Basically, it's filter + map.

Type parameters

Z

The value type of the new signal.

Value parameters

pf

A partial function which for the original value of the type V may produce a value of the type Z.

Attributes

Returns

A new signal with values of the type Z, holding the value produced from the original signal's value by the partial function, or empty if that's not possible.

Inherited from:
Signal
final inline def combine[Z, Y](other: Signal[Z])(f: (V, Z) => Y): Signal[Y]

Combines the current values of this and another signal of the same or different types V and Z to produce a signal with the value of yet another type Y. Basically, zip + map.

Combines the current values of this and another signal of the same or different types V and Z to produce a signal with the value of yet another type Y. Basically, zip + map.

Type parameters

Y

The value type of the new signal.

Z

The value type of the other signal.

Value parameters

f

The function which combines the current values of both parent signals to produce the value of the new signal.

other

The other signal with values of the same or a different type.

Attributes

Returns

A new signal with the value of the type Y.

Inherited from:
Signal
final def contains(value: V)(using ExecutionContext): Future[Boolean]

A shortcut that checks if the current value (or the first value after initialization) is the given one.

A shortcut that checks if the current value (or the first value after initialization) is the given one.

Value parameters

value

The value to test

Attributes

Returns

a future of boolean: true if the signal contains the given value, false otherwise

Note

Requires an ExecutionContext for async operations when the signal is empty

Inherited from:
Signal
final def currentValue: Option[V]

The current value of the signal. If the signal requires some initial work before accessing its value for the first time, it will be done exactly one time. Subsequently, this method will simply return the current value.

The current value of the signal. If the signal requires some initial work before accessing its value for the first time, it will be done exactly one time. Subsequently, this method will simply return the current value.

Please note that this will return an option of the value type. You may get a None if the signal is not initialized yet or if it was temporarily cleared and awaits another update. Usually, it's safer to use head or future and work with a future of the value type instead. And if you need to know if the signal is currently empty, use empty.

Attributes

Returns

The current value of the signal.

Inherited from:
Signal
def disableAutowiring(): this.type

Typically, a newly created event streams and signals are lazy in the sense that till there are no subscriptions to them, they will not execute any intermediate computations (e.g. assembled to it through maps, flatMaps, etc). After all, those computations would be ignored at the end. Only when a subscription is created, the computations are performed for the first time. disableAutowiring enforces those computations even if there are no subscribers. It can be useful if e.g. the computations perform side-effects or if it's important from the performance point of view to have the intermediate results ready when the subscriber is created.

Typically, a newly created event streams and signals are lazy in the sense that till there are no subscriptions to them, they will not execute any intermediate computations (e.g. assembled to it through maps, flatMaps, etc). After all, those computations would be ignored at the end. Only when a subscription is created, the computations are performed for the first time. disableAutowiring enforces those computations even if there are no subscribers. It can be useful if e.g. the computations perform side-effects or if it's important from the performance point of view to have the intermediate results ready when the subscriber is created.

Attributes

Returns

The current instance, so that disableAutoworing can be chained with other method calls.

Inherited from:
EventSource (hidden)
final def drop(n: Int): Signal[V]

Ignores a given number of new values from the original signal before starting to update to the consecutive ones.

Ignores a given number of new values from the original signal before starting to update to the consecutive ones.

Value parameters

n

The number of values to drop

Attributes

Returns

A new signal that drops n values and then starts to use all consecutive values

Inherited from:
Signal
final inline def dropWhile(p: V => Boolean): Signal[V]

Ignores new values while they fulfill the condition p. The first event that fails is emitted and all consecutive events as well, also those that would fulfill the condition.

Ignores new values while they fulfill the condition p. The first event that fails is emitted and all consecutive events as well, also those that would fulfill the condition.

Value parameters

p

The condition function

Attributes

Returns

A new signal that drops events while p is fulfilled

Inherited from:
Signal
final inline def either[Z](fallback: Signal[Z]): Signal[Either[Z, V]]

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

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

Type parameters

Z

The value type of the fallback signal.

Value parameters

fallback

Another signal of the same or different value type.

Attributes

Returns

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

Inherited from:
Signal
final inline def empty: Boolean

Checks if the signal is currently empty. A signal is usually empty just after creation, if it was not initialized with a value, and it still waits for the first value to be sent to it. Or it can be a constant Signal.empty[V].

Checks if the signal is currently empty. A signal is usually empty just after creation, if it was not initialized with a value, and it still waits for the first value to be sent to it. Or it can be a constant Signal.empty[V].

Attributes

Returns

true if the signal is empty, false otherwise.

See also
Inherited from:
Signal
final def exists(f: V => Boolean)(using ExecutionContext): Future[Boolean]

A shortcut that checks if the current value (or the first value after initialization) fulfills the given condition.

A shortcut that checks if the current value (or the first value after initialization) fulfills the given condition.

Value parameters

f

The condition tested on the signal's value

Attributes

Returns

a future of boolean: true if the signal's value fulfills the given condition, false otherwise

Note

Requires an ExecutionContext for async operations when the signal is empty

Inherited from:
Signal
final def filter(predicate: V => Boolean): Signal[V]

Creates a new Signal[V] which updates its value only if the new value of the original signal satisfies the filter, and changes to empty otherwise. Also, if the initial value of the original signal does not satisfy the filter, the new signal will start empty.

Creates a new Signal[V] which updates its value only if the new value of the original signal satisfies the filter, and changes to empty otherwise. Also, if the initial value of the original signal does not satisfy the filter, the new signal will start empty.

Value parameters

predicate

A filtering function which for any value of the original signal returns true or false.

Attributes

Returns

A new signal of the same value type.

Inherited from:
Signal
final inline def flatMap[Z](f: V => Signal[Z]): Signal[Z]

Creates a new Signal[Z] by mapping each event of the original Signal[V] to a new signal and switching to it. The usual use case is to create a new complex signal not as one big entity with the value being the result of computations based on a lot of data at once, but to break it into simpler signals connected by flatMaps. At each step the used signal produces an intermediate value and recomputing that value is not necessary again until the values used to compute that one are changed too.

Creates a new Signal[Z] by mapping each event of the original Signal[V] to a new signal and switching to it. The usual use case is to create a new complex signal not as one big entity with the value being the result of computations based on a lot of data at once, but to break it into simpler signals connected by flatMaps. At each step the used signal produces an intermediate value and recomputing that value is not necessary again until the values used to compute that one are changed too.

Type parameters

Z

The value type of the new signal.

Value parameters

f

The function mapping each event of type v to a signal of the type Z.

Attributes

Returns

A new or already existing signal to which we switch as the result of a change in the value of the original signal.

Inherited from:
Signal
final inline def flatten[Z](using V <:< Signal[Z]): Signal[Z]

Flattens a signal whose value type is also a signal.

Flattens a signal whose value type is also a signal.

Type parameters

Z

The type of the value of the nested signal.

Attributes

Returns

A new signal of the value type the same as the value type of the nested signal.

Inherited from:
Signal
final inline def foreach(body: V => Unit)(using executionContext: ExecutionContext, eventContext: EventContext = ...): Unit

An alias for the on method with the implicit scala.concurrent.ExecutionContext.

An alias for the on method with the implicit scala.concurrent.ExecutionContext.

Attributes

Inherited from:
EventSource (hidden)
final def future: Future[V]

A future with the current value of the signal. The future will finish immediately with the current value of the signal if the value is already set. If the signal is empty, the future will finish when the next update sets the value.

A future with the current value of the signal. The future will finish immediately with the current value of the signal if the value is already set. If the signal is empty, the future will finish when the next update sets the value.

Attributes

Returns

The current value of the signal or the value it will be set to in the next update.

Inherited from:
Signal
final inline def groupBy(p: V => Boolean): Signal[Seq[V]]

Groups values in sequences of uneven size and uses each sequence as one value. The size of each sequence is decided by a condition. If the new value fulfills the condition, all values already stored in a buffer are used as one new value (a sequence), and the new value becomes the first element of a new sequence (it's not released yet). Otherwise, the value is added to the buffer and the result value is not changed.

Groups values in sequences of uneven size and uses each sequence as one value. The size of each sequence is decided by a condition. If the new value fulfills the condition, all values already stored in a buffer are used as one new value (a sequence), and the new value becomes the first element of a new sequence (it's not released yet). Otherwise, the value is added to the buffer and the result value is not changed.

Value parameters

p

A condition function

Attributes

Returns

A new signal where the value type is a sequence of original values

Inherited from:
Signal
final inline def grouped(n: Int): Signal[Seq[V]]

Groups values in sequences of even size and uses each sequence as one value.

Groups values in sequences of even size and uses each sequence as one value.

Value parameters

n

The size of the sequence

Attributes

Returns

A new signal where the value type is a sequence of original values

Inherited from:
Signal
final def hasSubscribers: Boolean

Checks if there are any subscribers registered in this EventRelay.

Checks if there are any subscribers registered in this EventRelay.

Attributes

Returns

true if any subscribers are registered, false otherwise

Inherited from:
EventSource (hidden)
final inline def head: Future[V]

An alias to the future method.

An alias to the future method.

Attributes

Inherited from:
Signal
def ignoreExceptions(f: Throwable => Unit): Signal[V]

Creates a new signal which, if a further transformation fails with an exception, does not update its value, but also allows for a side-effect, e.g. logging that the exception was caught. Note: This recovery guard must be placed before the risky transformation, not after, as e.g. in the case of scala.util.Try.recover.

Creates a new signal which, if a further transformation fails with an exception, does not update its value, but also allows for a side-effect, e.g. logging that the exception was caught. Note: This recovery guard must be placed before the risky transformation, not after, as e.g. in the case of scala.util.Try.recover.

Value parameters

f

A function that is triggered when the exception is caught

Attributes

Returns

A new signal of the same event type and the recovery guard

Inherited from:
Signal

Creates a new signal which, if a further transformation fails with an exception, behaves as if nothing happened. Note: This recovery guard must be placed before the risky transformation, not after, as e.g. in the case of scala.util.Try.recover.

Creates a new signal which, if a further transformation fails with an exception, behaves as if nothing happened. Note: This recovery guard must be placed before the risky transformation, not after, as e.g. in the case of scala.util.Try.recover.

Attributes

Returns

A new signal of the same value type and the recovery guard

Inherited from:
Signal
def ignoreExceptionsWith(pf: PartialFunction[Throwable, Unit]): Signal[V]

Creates a new signal which, if a further transformation fails with an exception that is handled by a provided partial function, will ignore the exception and allow for a side-effect to take place. Note: This recovery guard must be placed before the risky transformation, not after, as e.g. in the case of scala.util.Try.recoverWith.

Creates a new signal which, if a further transformation fails with an exception that is handled by a provided partial function, will ignore the exception and allow for a side-effect to take place. Note: This recovery guard must be placed before the risky transformation, not after, as e.g. in the case of scala.util.Try.recoverWith.

Value parameters

pf

A partial function transforming an exception into a side-effect

Attributes

Returns

A new signal of the same value type and the recovery guard

Inherited from:
Signal
final def indexed: IndexedSignal[V]

Provides Indexed functionality to the original signal

Provides Indexed functionality to the original signal

Attributes

Returns

A new indexed signal or the original one if it's already indexed

Inherited from:
Signal
final inline def map[Z](f: V => Z): Signal[Z]

Creates a new Signal[Z] by mapping the value of the type V of this signal.

Creates a new Signal[Z] by mapping the value of the type V of this signal.

Type parameters

Z

The value type of the new signal.

Value parameters

f

The function mapping the value of the original signal into the value of the new signal.

Attributes

Returns

A new signal

Inherited from:
Signal
final inline def nand[Z](other: Signal[Z])(using V <:< Boolean, Z <:< Boolean): Signal[Boolean]

Assuming that both the value of this signal and the value of the other signal can be interpreted as a boolean, this method creates a new signal of type Boolean by applying logical NAND.

Assuming that both the value of this signal and the value of the other signal can be interpreted as a boolean, this method creates a new signal of type Boolean by applying logical NAND.

Value parameters

other

The other signal with the value type that can be interpreted as Boolean

Attributes

Returns

A new signal of Boolean.

Inherited from:
Signal
final inline def nor[Z](other: Signal[Z])(using V <:< Boolean, Z <:< Boolean): Signal[Boolean]

Assuming that both the value of this signal and the value of the other signal can be interpreted as a boolean, this method creates a new signal of type Boolean by applying logical NOR.

Assuming that both the value of this signal and the value of the other signal can be interpreted as a boolean, this method creates a new signal of type Boolean by applying logical NOR.

Value parameters

other

The other signal with the value type that can be interpreted as Boolean

Attributes

Returns

A new signal of Boolean.

Inherited from:
Signal
final inline def not(using V <:< Boolean): Signal[Boolean]

Assuming that the value of the signal can be interpreted as a boolean, this method creates a new signal of type Boolean with the value opposite to that of the original signal.

Assuming that the value of the signal can be interpreted as a boolean, this method creates a new signal of type Boolean with the value opposite to that of the original signal.

Attributes

Returns

A new signal of Boolean.

Inherited from:
Signal
final inline def on(ec: ExecutionContext)(body: V => Unit)(using eventContext: EventContext = ...): Unit

Creates a subscription to a function which will consume events in the given ExecutionContext. In simpler terms: A subscriber is a function which will receive events from the event source. For every event, the function will be executed in the given execution context - not necessarily the same as the one used for emitting the event. This allows for easy communication between parts of the program working in different execution contexts, e.g. the user interface and the database.

Creates a subscription to a function which will consume events in the given ExecutionContext. In simpler terms: A subscriber is a function which will receive events from the event source. For every event, the function will be executed in the given execution context - not necessarily the same as the one used for emitting the event. This allows for easy communication between parts of the program working in different execution contexts, e.g. the user interface and the database.

The subscription will be automatically enabled (Subscription.enable).

Value parameters

body

A function which consumes the event

ec

An ExecutionContext in which the given function will be executed.

eventContext

An EventContext which will register the subscription for further management (optional)

Attributes

Inherited from:
EventSource (hidden)
final inline def onCurrent(body: V => Unit)(using eventContext: EventContext = ...): Unit

Creates a subscription to a function which will consume events in the same ExecutionContext as the one in which the events are being emitted.

Creates a subscription to a function which will consume events in the same ExecutionContext as the one in which the events are being emitted.

Value parameters

body

A function which consumes the event

eventContext

an EventContext which will register the subscription for further management (optional)

Attributes

See also

EventSource.on The subscription will be automatically enabled (Subscription.enable).

Inherited from:
EventSource (hidden)
final def onFalse(using V <:< Boolean): Future[Unit]

Assuming that the value of the signal can be interpreted as a boolean, this method returns a future of type Unit which will finish with success when the value of the original signal is false.

Assuming that the value of the signal can be interpreted as a boolean, this method returns a future of type Unit which will finish with success when the value of the original signal is false.

val signal = Signal[Int](2)
signal.map(_ % 2 == 0).onFalse.foreach { _ => println("This is the first time the value of the signal is odd") }

Attributes

Returns

A new future which finishes either immediately or as soon as the value of the original signal is false.

Inherited from:
Signal
final inline def onPartialUpdate[Z](select: V => Z): Signal[V]

Creates a new signal of the same value type which changes its value to the changed value of the parent signal only if the given select function returns different results for the old and the new value. If the results of the select functions are equal, then even if the new value of the original signal is actually different from the old one, the value of the new signal stays the same.

Creates a new signal of the same value type which changes its value to the changed value of the parent signal only if the given select function returns different results for the old and the new value. If the results of the select functions are equal, then even if the new value of the original signal is actually different from the old one, the value of the new signal stays the same.

Consider the following example:

val parent = Signal[Int](3)
val oddEvenSwitch = parent.onPartialUpdate { _ % 2 == 0 }
oddEvenSwitch.foreach { _ => println(s"The value switched between odd and even") }

Here, the value of oddEvenSwitch will update only if the new value is even if the old one was odd and vice versa. So, if we publish new odd values to parent (1, 5, 9, 7, ...) the value of oddEvenSwitch will stay at 3. Only when we publish an even number to parent (say, 2), the value oddEventSwitch will change. And from now on it will stay like that until we publish an odd number to the parent.

Type parameters

Z

The type of the value returned by the select function.

Value parameters

select

A function mapping from the current value of the original signal to another value which will be used for checking if the new signal should update.

Attributes

Returns

A new signal of the same value type as this one, which updates only if the select function gives different results for the old and the new value of the parent signal.

Inherited from:
Signal
final def onTrue(using V <:< Boolean): Future[Unit]

Assuming that the value of the signal can be interpreted as a boolean, this method returns a future of type Unit which will finish with success when the value of the original signal is true.

Assuming that the value of the signal can be interpreted as a boolean, this method returns a future of type Unit which will finish with success when the value of the original signal is true.

val signal = Signal[Int](3)
signal.map(_ % 2 == 0).onTrue.foreach { _ => println("This is the first time the value of the signal is even") }

Attributes

Returns

A new future which finishes either immediately or as soon as the value of the original signal is true.

Inherited from:
Signal
final inline def or[Z](other: Signal[Z])(using V <:< Boolean, Z <:< Boolean): Signal[Boolean]

Assuming that both the value of this signal and the value of the other signal can be interpreted as a boolean, this method creates a new signal of type Boolean by applying logical OR.

Assuming that both the value of this signal and the value of the other signal can be interpreted as a boolean, this method creates a new signal of type Boolean by applying logical OR.

Value parameters

other

The other signal with the value type that can be interpreted as Boolean

Attributes

Returns

A new signal of Boolean.

Inherited from:
Signal
final def orElse(fallback: Signal[V]): Signal[V]

Creates a version of this signal which, if the parent signal becomes empty, temporarily uses the value of the given fallback signal. The moment the parent signal is set to a new value again, the new signal switches back to it. Only when both signals are empty, the new signal will become empty too.

Creates a version of this signal which, if the parent signal becomes empty, temporarily uses the value of the given fallback signal. The moment the parent signal is set to a new value again, the new signal switches back to it. Only when both signals are empty, the new signal will become empty too.

Value parameters

fallback

Another signal of the same value type.

Attributes

Returns

A new signal of the same value type.

Inherited from:
Signal
final inline def pipeTo(sourceSignal: SourceSignal[V])(using ec: EventContext = ...): Unit

A shorthand for registering a subscriber function in this signal whose only purpose is to publish changes to the value of this signal in another SourceSignal. The subscriber function will be called in the execution context of the original publisher.

A shorthand for registering a subscriber function in this signal whose only purpose is to publish changes to the value of this signal in another SourceSignal. The subscriber function will be called in the execution context of the original publisher.

Value parameters

ec

An EventContext which can be used to manage the subscription (optional).

sourceSignal

The signal in which changes to the value of this signal will be published.

Attributes

See also
Inherited from:
Signal
def recover(f: Throwable => V): Signal[V]

Creates a new signal which, if a further transformation fails with an exception, will set to a recovery value instead. Note: This recovery guard must be placed before the risky transformation, not after, as e.g. in the case of scala.util.Try.recover.

Creates a new signal which, if a further transformation fails with an exception, will set to a recovery value instead. Note: This recovery guard must be placed before the risky transformation, not after, as e.g. in the case of scala.util.Try.recover.

Value parameters

f

A function transforming an exception into a recovery value

Attributes

Returns

A new signal of the same value type and the recovery guard

Inherited from:
Signal
def recoverWith(pf: PartialFunction[Throwable, V]): Signal[V]

Creates a new signal which, if a further transformation fails with an exception that is handled by a provided partial function, will use a recovery value instead. Note: This recovery guard must be placed before the risky transformation, not after, as e.g. in the case of scala.util.Try.recoverWith.

Creates a new signal which, if a further transformation fails with an exception that is handled by a provided partial function, will use a recovery value instead. Note: This recovery guard must be placed before the risky transformation, not after, as e.g. in the case of scala.util.Try.recoverWith.

Value parameters

pf

A partial function transforming an exception into a recovery value

Attributes

Returns

A new signal of the same value type and the recovery guard

Inherited from:
Signal
final inline def sameAs[Z](other: Signal[Z]): Signal[Boolean]

Creates a boolean signal where the value is the result of comparison of current values in both the original signals. This method uses Scala equals internally and for the sake of consistency with how equals works in Scala, sameAs allows for comparison between values of different types - there still may exist a valid equals for them.

Creates a boolean signal where the value is the result of comparison of current values in both the original signals. This method uses Scala equals internally and for the sake of consistency with how equals works in Scala, sameAs allows for comparison between values of different types - there still may exist a valid equals for them.

If any of the original signals is empty, the result signal will stay empty as well.

Value parameters

other

The other signal used in comparison

Attributes

Returns

A new boolean signal

Inherited from:
Signal
final inline def scan[Z](zero: Z)(f: (Z, V) => Z): Signal[Z]

Creates a new signal with the value type Z where the change in the value is the result of applying a function which combines the previous value of type Z with the changed value of the type V of the parent signal.

Creates a new signal with the value type Z where the change in the value is the result of applying a function which combines the previous value of type Z with the changed value of the type V of the parent signal.

Type parameters

Z

The value type of the new signal.

Value parameters

f

The function which combines the current value of the new signal with the new, changed value of the parent (this) signal to produce a new value for the new signal (might be the same as the old one and then subscribers won't be notified).

zero

The initial value of the new signal.

Attributes

Returns

A new signal with the value of the type Z.

Todo

Test if it really works like that, the code is a bit complicated.

Inherited from:
Signal
final inline def splitAt(p: V => Boolean): (FiniteSignal[V], Signal[V])

Splits the signal into a finite signal that updates until the new value stops fulfilling the given condition, and another signal that picks up updating its value after the first stops.

Splits the signal into a finite signal that updates until the new value stops fulfilling the given condition, and another signal that picks up updating its value after the first stops.

Value parameters

p

The condition function

Attributes

Returns

A tuple of streams of the same event type

Inherited from:
Signal
final inline def splitAt(n: Int): (FiniteSignal[V], Signal[V])

Splits the signal into a finite signal that updates the given number of values and closes, and another signal that picks up updating its value after the first stops.

Splits the signal into a finite signal that updates the given number of values and closes, and another signal that picks up updating its value after the first stops.

Value parameters

n

The number of value updates to split the stream at

Attributes

Returns

A tuple of signals of the same event type

Inherited from:
Signal
def subscribe(subscriber: Subscriber): Unit

Adds a new subscriber instance. The implementing class should handle notifying this subscriber when a new event arrives. If this is the first subscriber, and disableAutowiring wasn't called previous, this will trigger a call to onWire.

Adds a new subscriber instance. The implementing class should handle notifying this subscriber when a new event arrives. If this is the first subscriber, and disableAutowiring wasn't called previous, this will trigger a call to onWire.

Value parameters

subscriber

An instance of a subscriber class, known to the class implementing this EventRelay

Attributes

Inherited from:
EventSource (hidden)
final inline def tail: Signal[V]

Attributes

Inherited from:
Signal
final def take(n: Int): TakeSignal[V]

Updates the value a given number of times and then closes

Updates the value a given number of times and then closes

Value parameters

n

The number of value updates

Attributes

Returns

A new signal that updates n times and closes

Inherited from:
Signal
final inline def takeWhile(p: V => Boolean): FiniteSignal[V]

Updates the value while it fulfills the condition p. The first update that fails closes the signal.

Updates the value while it fulfills the condition p. The first update that fails closes the signal.

Value parameters

p

The condition function

Attributes

Returns

A new signal that updates events while p is fulfilled

Inherited from:
Signal
final inline def throttle(delay: FiniteDuration): Signal[V]

Creates a throttled version of this signal which updates 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.

Creates a throttled version of this signal which updates 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.

Value parameters

delay

The time interval used for throttling.

Attributes

Returns

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

See also
Inherited from:
Signal
def unsubscribe(subscriber: Subscriber): Unit

Removes a previously registered subscriber instance. If this is the last subscriber, and disableAutowiring wasn't called previously, this will trigger a call to onUnwire.

Removes a previously registered subscriber instance. If this is the last subscriber, and disableAutowiring wasn't called previously, this will trigger a call to onUnwire.

Value parameters

subscriber

An instance of a subscriber class, known to the class implementing this EventRelay

Attributes

Inherited from:
EventSource (hidden)
def unsubscribeAll(): Unit

Empties the set of subscribers and calls unWire if disableAutowiring wasn't called before.

Empties the set of subscribers and calls unWire if disableAutowiring wasn't called before.

Attributes

Inherited from:
EventSource (hidden)
final inline def wired: Boolean

Returns true if the event source is currently wired to subscribers.

Returns true if the event source is currently wired to subscribers.

Attributes

Inherited from:
EventSource (hidden)
def withDefault(value: V): Signal[V]

A utility method that works like Signal#recover where every exception is replaced with a default value. Note: This recovery guard must be placed before the risky transformation, not after, as e.g. in the case of scala.util.Try.recover.

A utility method that works like Signal#recover where every exception is replaced with a default value. Note: This recovery guard must be placed before the risky transformation, not after, as e.g. in the case of scala.util.Try.recover.

Value parameters

value

The default value that's set if an exception is caught

Attributes

Returns

A new signal of the same value type and the recovery guard

Inherited from:
Signal
final inline def withFilter(predicate: V => Boolean): Signal[V]

An alias for filter used in the for/yield notation.

An alias for filter used in the for/yield notation.

This can be useful for more readable chains of asynchronous computations where at some point we want to wait until some condition is fulfilled:

val resultSignal = for {
a    <- signalA
b    <- signalB
true <- checkCondition(a, b)
c    <- signalC
} yield c

Here, resultSignal will be updated to the value of signalC only if the current values of signalA and signalB fulfill the condition. If the check fails, resultSignal will become empty until signalA or signalB changes its value and the new pair fulfills the condition.

Value parameters

predicate

A filtering function which for any value of the original signal returns true or false.

Attributes

Returns

A new signal of the same value type.

Inherited from:
Signal
final inline def xor[Z](other: Signal[Z])(using V <:< Boolean, Z <:< Boolean): Signal[Boolean]

Assuming that both the value of this signal and the value of the other signal can be interpreted as a boolean, this method creates a new signal of type Boolean by applying logical XOR.

Assuming that both the value of this signal and the value of the other signal can be interpreted as a boolean, this method creates a new signal of type Boolean by applying logical XOR.

Value parameters

other

The other signal with the value type that can be interpreted as Boolean

Attributes

Returns

A new signal of Boolean.

Inherited from:
Signal
final inline def zip[Z](other: Signal[Z]): Signal[(V, Z)]

Zips this signal with the given one.

Zips this signal with the given one.

Type parameters

Z

The type of the values of the other signal.

Value parameters

other

The other signal with values of the same or a different type.

Attributes

Returns

A new signal with values being tuples of the value of this signal and the other one. The value of the other signal will be updated every time this or the other signal's value is updated.

Inherited from:
Signal
final inline def |(sourceSignal: SourceSignal[V])(using ec: EventContext = ...): Unit

An alias for pipeTo.

An alias for pipeTo.

Attributes

Inherited from:
Signal
final inline def ||[Z](other: Signal[Z])(using V <:< Boolean, Z <:< Boolean): Signal[Boolean]

An alias to or.

An alias to or.

Value parameters

other

The other signal with the value type that can be interpreted as Boolean

Attributes

Returns

A new signal of Boolean.

Inherited from:
Signal

Inherited fields

final lazy val onChanged: Stream[V]

A stream where each event is a new value of the signal. Every time the value of the signal changes - actually changes to another value - the new value will be published in this stream. The events in the stream are guaranteed to differ. It's not possible to get two equal events one after another.

A stream where each event is a new value of the signal. Every time the value of the signal changes - actually changes to another value - the new value will be published in this stream. The events in the stream are guaranteed to differ. It's not possible to get two equal events one after another.

Attributes

Inherited from:
Signal
final lazy val onUpdated: Stream[(Option[V], V)]

a stream where each event is a tuple of the old and the new value of the signal. Every time the value of the signal changes - actually changes to another value - the new value will be published in this stream, together with the old value which you can use to check what exactly changed. The old value is wrapped in an Option: if the signal was previously empty, the old value will be None otherwise it will be Some[V]. The values are guaranteed to differ, i.e. if you get a tuple (Some(oldValue), newValue) then oldValue != newValue.

a stream where each event is a tuple of the old and the new value of the signal. Every time the value of the signal changes - actually changes to another value - the new value will be published in this stream, together with the old value which you can use to check what exactly changed. The old value is wrapped in an Option: if the signal was previously empty, the old value will be None otherwise it will be Some[V]. The values are guaranteed to differ, i.e. if you get a tuple (Some(oldValue), newValue) then oldValue != newValue.

Attributes

Inherited from:
Signal