commonMain.org.brightify.hyperdrive.util.bridge.NullableMutableStateFlowWrapper.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of runtime Show documentation
Show all versions of runtime Show documentation
Hyperdrive implementation that's needed for observations and such
package org.brightify.hyperdrive.util.bridge
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.map
public open class NullableMutableStateFlowWrapper(
private val getter: () -> T?,
private val setter: (T?) -> Unit,
private val origin: Flow
): NullableStateFlowWrapper(getter, origin) {
override var value: T?
get() = getter()
set(newValue) {
setter(newValue)
}
public companion object {
public fun wrap(flow: MutableStateFlow): NullableMutableStateFlowWrapper {
return NullableMutableStateFlowWrapper(getter = { flow.value }, setter = { flow.value = it }, origin = flow)
}
public fun wrapNonNullList(flow: MutableStateFlow?>): NullableMutableStateFlowWrapper> {
return NullableMutableStateFlowWrapper(getter = { flow.value?.let(::NonNullListWrapper) },
{ flow.value = it?.origin },
flow.map { it?.let(::NonNullListWrapper) })
}
public fun wrapNullableList(flow: MutableStateFlow?>): NullableMutableStateFlowWrapper> {
return NullableMutableStateFlowWrapper(getter = { flow.value?.let(::NullableListWrapper) },
{ flow.value = it?.origin },
flow.map { it?.let(::NullableListWrapper) })
}
}
}