All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.org.brightify.hyperdrive.util.bridge.NullableMutableStateFlowWrapper.kt Maven / Gradle / Ivy

There is a newer version: 0.1.159
Show newest version
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) })
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy