Package-level declarations

Types

Link copied to clipboard
class ClockWrapper(val clock: Clock)

This class simply wraps a plain Clock.

Link copied to clipboard
Link copied to clipboard
actual typealias PlatformLocale = ULocale
expect class PlatformLocale
actual typealias PlatformLocale = Locale
actual typealias PlatformLocale = Locale
typealias PlatformLocale = Locale
Link copied to clipboard
data class TickingValue<out T>(val value: T, val nextTick: Duration?)

This class holds a value of type T and a Duration that indicates how much time needs to pass before recalculating value is required (i.e. how long since its production nextTick is valid for).

Link copied to clipboard
fun interface TickingValueProvider<T>

Simple interface that allows implementors to provide a TickingValue for a given reference point.

Link copied to clipboard
data class Zoned<out T>(val value: T, val timeZone: TimeZone)

Hodler for a generic value T that is associated with a TimeZone

Properties

Link copied to clipboard
actual val SYSTEM_CLOCK: StateFlow<ClockWrapper>

Returns a Flow that emits ClockWrapper of Clock.System every time the system clock updates. Initially, a value is always emitted a first time, and it later waits for changes.

expect val SYSTEM_CLOCK: StateFlow<ClockWrapper>

Returns a Flow that emits ClockWrapper of Clock.System every time the system clock updates. Initially, a value is always emitted a first time, and it later waits for changes.

actual val SYSTEM_CLOCK: StateFlow<ClockWrapper>

Returns a Flow that emits ClockWrapper of Clock.System every time the system clock updates. Initially, a value is always emitted a first time, and it later waits for changes.

actual val SYSTEM_CLOCK: StateFlow<ClockWrapper>

Returns a Flow that emits ClockWrapper of Clock.System every time the system clock updates. Initially, a value is always emitted a first time, and it later waits for changes.

Link copied to clipboard
actual val SYSTEM_TIMEZONE: StateFlow<TimeZone>

Returns a Flow that emits the current system TimeZone every time it changes. Initially, the current system TimeZone is always emitted a first time.

expect val SYSTEM_TIMEZONE: StateFlow<TimeZone>

Returns a Flow that emits the current system TimeZone every time it changes. Initially, the current system TimeZone is always emitted a first time.

actual val SYSTEM_TIMEZONE: StateFlow<TimeZone>

Returns a Flow that emits the current system TimeZone every time it changes. Initially, the current system TimeZone is always emitted a first time.

actual val SYSTEM_TIMEZONE: StateFlow<TimeZone>

Returns a Flow that emits the current system TimeZone every time it changes. Initially, the current system TimeZone is always emitted a first time.

Functions

Link copied to clipboard
suspend fun <T> TickingValueProvider<T>.collect(clock: Clock, timeZone: TimeZone, maxTick: Duration? = null, initialReference: Zoned<Instant> = Zoned(clock.now(), timeZone), initialValue: TickingValue<T> = this.provide(initialReference), collector: suspend (T) -> Unit)

Function that calls collector with the TickingValue.value calculated by this TickingValueProvider.provide each time there is a new value.

Link copied to clipboard
fun <T1, T2, R> TickingValue<T1>.combine(other: TickingValue<T2>, transform: (T1, T2) -> R): TickingValue<R>

Combines two different TickingValues.

Link copied to clipboard
fun <T, R> TickingValue<T>.flatMap(transform: (T) -> TickingValue<R>): TickingValue<R>

Transforms this TickingValue using the transform function. The resulting TickingValue.nextTick will be the min of the two, see also withNextTickAtMost.

Link copied to clipboard

Returns the current default locale (i.e. system locale)

Returns the current default locale (i.e. system locale)

Returns the current default locale (i.e. system locale)

Returns the current default locale (i.e. system locale)

Link copied to clipboard

Returns the PlatformLocale corresponding to the given Bcp47 tag.

Returns the PlatformLocale corresponding to the given Bcp47 tag.

Returns the PlatformLocale corresponding to the given Bcp47 tag.

Returns the PlatformLocale corresponding to the given Bcp47 tag.

Returns the PlatformLocale corresponding to the given Bcp47 tag.

Link copied to clipboard
fun <T, R> TickingValueProvider<T>.map(transform: (localized: TickingValue<T>, reference: Zoned<Instant>) -> TickingValue<R>): TickingValueProvider<R>

Simple mapping function that returns a new TickingValueProvider that, upon TickingValueProvider.provide, calls transform with the result of provide and its reference point, and returns the output of transform.

fun <T, R> TickingValue<T>.map(transform: (T) -> R): TickingValue<R>

Transforms the TickingValue.value from this instance from type T to R using transform and returns a new TickingValue with it and the same TickingValue.nextTick.

Link copied to clipboard
fun <T, R> Zoned<T>.mapValue(transform: (T) -> R): Zoned<R>

Returns a new Zoned with the same Zoned.timeZone and the value returned by transform.

Link copied to clipboard
operator fun Zoned<Instant>.minus(duration: Duration): Zoned<Instant>
Link copied to clipboard
operator fun Zoned<Instant>.plus(duration: Duration): Zoned<Instant>
Link copied to clipboard
fun <T> TickingValueProvider<T>.toFlow(clock: Flow<ClockWrapper> = SYSTEM_CLOCK, timeZone: Flow<TimeZone> = SYSTEM_TIMEZONE, maxTick: Duration? = null): Flow<T>

Uses the given clock and timeZone flows to compute the reference point passed to TickingValueProvider.provide and returns the resulting Flow. This function assumes that each Clock emitted by the clock flow moves forward linearly.

Link copied to clipboard
fun Zoned<Instant>.toLocalDateTime(): LocalDateTime

Returns a civil datetime value that this instant Zoned.value has in the specified Zoned.timeZone.

Link copied to clipboard

Returns a TickingValue with the same TickingValue.value and with the next tick being the min of its value and TickingValue.nextTick.