commonMain.org.brightify.hyperdrive.util.bridge.NonNullFlowWrapper.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.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))
}
}
}