Skip to content
Snippets Groups Projects
Verified Commit 167fa1ad authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

feat: correct issue with state holder api

parent e89b04e2
Branches
Tags
No related merge requests found
...@@ -15,4 +15,4 @@ plugins { ...@@ -15,4 +15,4 @@ plugins {
} }
group = "de.justjanne.libquassel" group = "de.justjanne.libquassel"
version = "0.8.0" version = "0.8.1"
...@@ -12,14 +12,17 @@ package de.justjanne.libquassel.protocol.util ...@@ -12,14 +12,17 @@ package de.justjanne.libquassel.protocol.util
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
@ExperimentalCoroutinesApi @ExperimentalCoroutinesApi
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun <T> Flow<StateHolder<T>?>.flatMap(): Flow<T?> = inline fun <T> Flow<StateHolder<T>?>.flatMap(): Flow<T?> =
flatMapLatest { it?.flow() ?: emptyFlow() } flatMapLatest { it?.flow() ?: flowOf(null) }
@ExperimentalCoroutinesApi @ExperimentalCoroutinesApi
inline fun <reified T> Flow<Iterable<StateHolder<T>>?>.combineLatest(): Flow<List<T>> = inline fun <reified T> Flow<Iterable<StateHolder<T>>?>.combineLatest(): Flow<List<T>> =
flatMapLatest { combine(it?.map(StateHolder<T>::flow).orEmpty(), ::listOf) } flatMapLatest {
if (it != null) combine(it.map(StateHolder<T>::flow), ::listOf)
else flowOf(emptyList())
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment