Behavior

sealed interface Behavior<out A>(source)

A behavior is a value of type A whose value varies over time.

It can be thought of from a denotational perspective as a function (Time) -> A.

Visually, you can think of a Behavior as a graph where the x-axis represents time, the y-axis represents different values of A, and for each time value there is a different value of A, for example:

^
| * **
| * ** *
| * * * *
| *** ***
-------------------->

Behaviors have no other restrictions, and can be either continuous or discrete functions of time. In yafrl, behaviors can even be nondeterministic, acting as good representations of external inputs to a program.

Inheritors

Types

Link copied to clipboard
object Companion
Link copied to clipboard
class Continuous<A>(vectorSpace: Lazy<VectorSpace<A>>, f: (Duration) -> A) : Behavior<A>

A generic continuous function of time.

Link copied to clipboard
class Impulse<A, B>(zeroValue: B, event: Event<A>, onEvent: (A) -> B) : Behavior<B>

A behavior representing a dirac impulse derived from an event.

Link copied to clipboard
class Polynomial<A>(vectorSpace: VectorSpace<A>, coefficients: List<A>) : Behavior<A>

A polynomial in time.

Link copied to clipboard
class Sampled<A>(val id: BehaviorID, instance: () -> VectorSpace<A>, current: () -> A) : Behavior<A>

A non-numeric behavior derived from sampling an external signal.

Link copied to clipboard
class Sum<A>(val vectorSpace: VectorSpace<A>, val first: Behavior<A>, val second: Behavior<A>) : Behavior<A> , VectorSpace<A>

Properties

Link copied to clipboard

Functions

Link copied to clipboard
open fun <B> flatMap(f: SampleScope.(A) -> Behavior<B>): Behavior<B>
Link copied to clipboard
inline fun <T> Behavior<T>.integrate(initial: T? = null): Behavior<T>

Integrate the behavior with respect to the current Timeline's clock time.

fun <T> Behavior<T>.integrate(vectorSpace: VectorSpace<T>, initial: T? = null): Behavior<T>

Integrate the behavior with respect to the current Timeline's clock time, supplying an explicit VectorSpace instance.

Link copied to clipboard
inline fun <T> Behavior<T>.integrateWith(initial: T, noinline accum: SampleScope.(T, T) -> T): Behavior<T>
fun <T> Behavior<T>.integrateWith(vectorSpace: VectorSpace<T>, initial: T, accum: SampleScope.(T, T) -> T): Behavior<T>
Link copied to clipboard
open fun <B> map(f: SampleScope.(A) -> B): Behavior<B>
Link copied to clipboard
abstract fun measureImpulses(time: Duration, dt: Duration): A

Used to support dirac impulses in behaviors.

Link copied to clipboard
operator fun Behavior<Boolean>.not(): Behavior<Boolean>

Negate the value of the behavior at all times.

Link copied to clipboard
@JvmName(name = "plusFloat2")
operator fun Behavior<Float2>.plus(other: Behavior<Float2>): Behavior<Float2>
@JvmName(name = "plusFloat3")
operator fun Behavior<Float3>.plus(other: Behavior<Float3>): Behavior<Float3>
@JvmName(name = "plusDouble")
operator fun Behavior<Double>.plus(other: Behavior<Double>): Behavior<Double>
@JvmName(name = "plusFloat")
operator fun Behavior<Float>.plus(other: Behavior<Float>): Behavior<Float>
@JvmName(name = "plusInt")
operator fun Behavior<Int>.plus(other: Behavior<Int>): Behavior<Int>
Link copied to clipboard
open fun sample(times: Event<Any?> = Timeline.currentTimeline().clock): Event<A>

Sample a Behavior at the occurrences of times, returning a new Event with the values of the behavior at those times.

Link copied to clipboard
open fun sampleState(times: Event<Any?> = Timeline.currentTimeline().timeBehavior.updated()): Signal<A>

Sample a Behavior to produce a Signal.

Link copied to clipboard
abstract fun sampleValueAt(time: Duration): A

Calculates the value at the specified time.

Link copied to clipboard
open fun transformTime(transform: (Duration) -> Duration): Behavior<A>

Apply a function to the time used to sample the behavior.

Link copied to clipboard
open fun until(event: Event<Behavior<@UnsafeVariance A>>): Behavior<A>

Constructs a new behavior whose values are equal to those of this behavior up until event is fired, at which point the behavior's value will switch to match the values of the event's inner behavior.