1
1
package com.hoc081098.flowext
2
2
3
3
import kotlinx.coroutines.CoroutineStart
4
+ import kotlinx.coroutines.InternalCoroutinesApi
4
5
import kotlinx.coroutines.channels.Channel
5
6
import kotlinx.coroutines.channels.onSuccess
6
7
import kotlinx.coroutines.coroutineScope
@@ -16,6 +17,7 @@ import kotlinx.coroutines.launch
16
17
* @param other Second [Flow]
17
18
* @param transform A transform function to apply to each value from self combined with the latest value from the second [Flow], if any.
18
19
*/
20
+ @InternalCoroutinesApi // TODO: Remove InternalCoroutinesApi (https://github.com/Kotlin/kotlinx.coroutines/issues/3078)
19
21
public fun <A , B , R > Flow<A>.withLatestFrom (
20
22
other : Flow <B >,
21
23
transform : suspend (A , B ) -> R
@@ -25,7 +27,7 @@ public fun <A, B, R> Flow<A>.withLatestFrom(
25
27
val otherValues = Channel <Any >(Channel .CONFLATED )
26
28
launch(start = CoroutineStart .UNDISPATCHED ) {
27
29
other.collect {
28
- return @collect otherValues.send(it ? : NullValue )
30
+ return @collect otherValues.send(it ? : NULL_VALUE )
29
31
}
30
32
}
31
33
@@ -38,14 +40,15 @@ public fun <A, B, R> Flow<A>.withLatestFrom(
38
40
emit(
39
41
transform(
40
42
value,
41
- NullValue .unbox(lastValue ? : return @collect)
43
+ NULL_VALUE .unbox(lastValue ? : return @collect)
42
44
),
43
45
)
44
46
}
45
47
}
46
48
}
47
49
}
48
50
51
+ @InternalCoroutinesApi // TODO: Remove InternalCoroutinesApi (https://github.com/Kotlin/kotlinx.coroutines/issues/3078)
49
52
@Suppress(" NOTHING_TO_INLINE" )
50
53
public inline fun <A , B > Flow<A>.withLatestFrom (other : Flow <B >): Flow <Pair <A , B >> =
51
54
withLatestFrom(other) { a, b -> a to b }
0 commit comments