org.hnau.base.data.outdatable.Outdatable.kt Maven / Gradle / Ivy
package org.hnau.base.data.outdatable
import org.hnau.base.data.Time
import org.hnau.base.extensions.boolean.checkTruth
import org.hnau.base.extensions.time.now
class Outdatable @PublishedApi internal constructor(
@PublishedApi
internal val value: T,
@PublishedApi
internal val actualTill: Time? = null
) {
companion object {}
@Suppress("DEPRECATION")
val forceValue
get() = value
@Suppress("DEPRECATION")
@PublishedApi
internal val isActual
get() = actualTill != null && actualTill >= Time.now()
@Suppress("DEPRECATION")
inline fun checkActual(
ifActual: (T) -> R,
ifOutdated: () -> R
) = isActual.checkTruth(
ifTrue = { ifActual(value) },
ifFalse = ifOutdated
)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy