Skip to content

Commit

Permalink
flow: fix recursion in combineTransform<T1, T2, R>()
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach authored and qwwdfsad committed Aug 25, 2019
1 parent 9acde74 commit 1f5ab53
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion kotlinx-coroutines-core/common/src/flow/operators/Zip.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ public fun <T1, T2, R> combineTransform(
flow: Flow<T1>,
flow2: Flow<T2>,
@BuilderInference transform: suspend FlowCollector<R>.(a: T1, b: T2) -> Unit
): Flow<R> = combineTransform(flow, flow2, transform)
): Flow<R> = combineTransform(flow, flow2) { args: Array<*> ->
transform(
args[0] as T1,
args[1] as T2
)
}

/**
* Returns a [Flow] whose values are generated with [transform] function by combining
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ class CombineIterableTest : CombineTestBase() {
combineOriginal(listOf(this, other)) { args -> transform(args[0] as T1, args[1] as T2) }
}

class CombineTransformAdapterTest : CombineTestBase() {
override fun <T1, T2, R> Flow<T1>.combineLatest(other: Flow<T2>, transform: suspend (T1, T2) -> R): Flow<R> =
combineTransformOriginal(flow = this, flow2 = other) { a1, a2 -> emit(transform(a1, a2)) }
}

class CombineTransformVarargAdapterTest : CombineTestBase() {
override fun <T1, T2, R> Flow<T1>.combineLatest(other: Flow<T2>, transform: suspend (T1, T2) -> R): Flow<R> =
combineTransformOriginal(this, other) { args: Array<Any?> -> emit(transform(args[0] as T1, args[1] as T2)) }
Expand Down

0 comments on commit 1f5ab53

Please sign in to comment.