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

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

There is a newer version: 0.1.159
Show newest version
package org.brightify.hyperdrive.util.bridge

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map

public open class NonNullFlowWrapper(
    private val origin: Flow
): Flow by origin {
    public open fun watch(
        onNext: (T) -> Unit,
        onError: (Exception) -> Unit,
        onCompleted: () -> Unit,
        coroutineScope: CoroutineScope = MainScope()
    ): FlowWrapperWatchToken = FlowWrapperWatchToken(this, coroutineScope, onNext, onError, onCompleted)

    public companion object {
        public fun  wrap(flow: Flow): NonNullFlowWrapper {
            return NonNullFlowWrapper(origin = flow)
        }

        public fun  wrapNonNullList(flow: Flow>): NonNullFlowWrapper> {
            return NonNullFlowWrapper(flow.map(::NonNullListWrapper))
        }

        public fun  wrapNullableList(flow: Flow>): NonNullFlowWrapper> {
            return NonNullFlowWrapper(flow.map(::NullableListWrapper))
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy