-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updating Gradle Wrapper * Adding Coroutines Module * PR feedback * PR feedback * Adding stub test class * adding test for combine extension functions * matching coroutines package name * fixing tests * fixing build * adding path fix to codecov.yml * fixing build
- Loading branch information
Showing
7 changed files
with
267 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ coverage: | |
patch: off | ||
fixes: | ||
- "com/juul/tuulbox/collections::" | ||
- "com/juul/tuulbox/coroutines/flow::" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
public final class com/juul/tuulbox/coroutines/flow/FlowsKt { | ||
public static final fun combine (Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function7;)Lkotlinx/coroutines/flow/Flow; | ||
public static final fun combine (Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function8;)Lkotlinx/coroutines/flow/Flow; | ||
public static final fun combine (Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function9;)Lkotlinx/coroutines/flow/Flow; | ||
public static final fun combine (Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function10;)Lkotlinx/coroutines/flow/Flow; | ||
public static final fun combine (Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function11;)Lkotlinx/coroutines/flow/Flow; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
plugins { | ||
id 'org.jetbrains.kotlin.jvm' | ||
id 'org.jmailen.kotlinter' | ||
id 'jacoco' | ||
id 'maven-publish' | ||
} | ||
|
||
apply from: rootProject.file('gradle/kotlin.gradle') | ||
apply from: rootProject.file('gradle/jacoco.gradle') | ||
apply from: rootProject.file('gradle/publish.gradle') | ||
|
||
dependencies { | ||
api deps.kotlin.stdlib | ||
api deps.kotlin.coroutines | ||
testImplementation deps.kotlin.junit | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
@file:Suppress("UNCHECKED_CAST") | ||
|
||
package com.juul.tuulbox.coroutines.flow | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.combine | ||
|
||
/** | ||
* Returns a [Flow] whose values are generated with [transform] function by combining | ||
* the most recently emitted values by each flow. | ||
*/ | ||
inline fun <T1, T2, T3, T4, T5, T6, R> combine( | ||
flow: Flow<T1>, | ||
flow2: Flow<T2>, | ||
flow3: Flow<T3>, | ||
flow4: Flow<T4>, | ||
flow5: Flow<T5>, | ||
flow6: Flow<T6>, | ||
crossinline transform: suspend (T1, T2, T3, T4, T5, T6) -> R | ||
): Flow<R> = combine(flow, flow2, flow3, flow4, flow5, flow6) { args: Array<*> -> | ||
transform( | ||
args[0] as T1, | ||
args[1] as T2, | ||
args[2] as T3, | ||
args[3] as T4, | ||
args[4] as T5, | ||
args[5] as T6 | ||
) | ||
} | ||
|
||
/** | ||
* Returns a [Flow] whose values are generated with [transform] function by combining | ||
* the most recently emitted values by each flow. | ||
*/ | ||
inline fun <T1, T2, T3, T4, T5, T6, T7, R> combine( | ||
flow: Flow<T1>, | ||
flow2: Flow<T2>, | ||
flow3: Flow<T3>, | ||
flow4: Flow<T4>, | ||
flow5: Flow<T5>, | ||
flow6: Flow<T6>, | ||
flow7: Flow<T7>, | ||
crossinline transform: suspend (T1, T2, T3, T4, T5, T6, T7) -> R | ||
): Flow<R> = combine(flow, flow2, flow3, flow4, flow5, flow6, flow7) { args: Array<*> -> | ||
transform( | ||
args[0] as T1, | ||
args[1] as T2, | ||
args[2] as T3, | ||
args[3] as T4, | ||
args[4] as T5, | ||
args[5] as T6, | ||
args[6] as T7 | ||
) | ||
} | ||
|
||
/** | ||
* Returns a [Flow] whose values are generated with [transform] function by combining | ||
* the most recently emitted values by each flow. | ||
*/ | ||
inline fun <T1, T2, T3, T4, T5, T6, T7, T8, R> combine( | ||
flow: Flow<T1>, | ||
flow2: Flow<T2>, | ||
flow3: Flow<T3>, | ||
flow4: Flow<T4>, | ||
flow5: Flow<T5>, | ||
flow6: Flow<T6>, | ||
flow7: Flow<T7>, | ||
flow8: Flow<T8>, | ||
crossinline transform: suspend (T1, T2, T3, T4, T5, T6, T7, T8) -> R | ||
): Flow<R> = combine(flow, flow2, flow3, flow4, flow5, flow6, flow7, flow8) { args: Array<*> -> | ||
transform( | ||
args[0] as T1, | ||
args[1] as T2, | ||
args[2] as T3, | ||
args[3] as T4, | ||
args[4] as T5, | ||
args[5] as T6, | ||
args[6] as T7, | ||
args[7] as T8 | ||
) | ||
} | ||
|
||
/** | ||
* Returns a [Flow] whose values are generated with [transform] function by combining | ||
* the most recently emitted values by each flow. | ||
*/ | ||
inline fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, R> combine( | ||
flow: Flow<T1>, | ||
flow2: Flow<T2>, | ||
flow3: Flow<T3>, | ||
flow4: Flow<T4>, | ||
flow5: Flow<T5>, | ||
flow6: Flow<T6>, | ||
flow7: Flow<T7>, | ||
flow8: Flow<T8>, | ||
flow9: Flow<T9>, | ||
crossinline transform: suspend (T1, T2, T3, T4, T5, T6, T7, T8, T9) -> R | ||
): Flow<R> = combine(flow, flow2, flow3, flow4, flow5, flow6, flow7, flow8, flow9) { args: Array<*> -> | ||
transform( | ||
args[0] as T1, | ||
args[1] as T2, | ||
args[2] as T3, | ||
args[3] as T4, | ||
args[4] as T5, | ||
args[5] as T6, | ||
args[6] as T7, | ||
args[7] as T8, | ||
args[8] as T9 | ||
) | ||
} | ||
|
||
/** | ||
* Returns a [Flow] whose values are generated with [transform] function by combining | ||
* the most recently emitted values by each flow. | ||
*/ | ||
inline fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R> combine( | ||
flow: Flow<T1>, | ||
flow2: Flow<T2>, | ||
flow3: Flow<T3>, | ||
flow4: Flow<T4>, | ||
flow5: Flow<T5>, | ||
flow6: Flow<T6>, | ||
flow7: Flow<T7>, | ||
flow8: Flow<T8>, | ||
flow9: Flow<T9>, | ||
flow10: Flow<T10>, | ||
crossinline transform: suspend (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) -> R | ||
): Flow<R> = combine(flow, flow2, flow3, flow4, flow5, flow6, flow7, flow8, flow9, flow10) { args: Array<*> -> | ||
transform( | ||
args[0] as T1, | ||
args[1] as T2, | ||
args[2] as T3, | ||
args[3] as T4, | ||
args[4] as T5, | ||
args[5] as T6, | ||
args[6] as T7, | ||
args[7] as T8, | ||
args[8] as T9, | ||
args[9] as T10 | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package com.juul.tuulbox.coroutines.flow | ||
|
||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlinx.coroutines.flow.flowOf | ||
import kotlinx.coroutines.flow.single | ||
import kotlinx.coroutines.runBlocking | ||
|
||
class CombineParametersTest { | ||
|
||
@Test | ||
fun testSixParameters() = runBlocking { | ||
val flow = combine( | ||
flowOf("1"), | ||
flowOf(2), | ||
flowOf("3"), | ||
flowOf(4.toByte()), | ||
flowOf(null), | ||
flowOf("6") | ||
) { a, b, c, d, e, f -> | ||
a + b + c + d + e + f | ||
} | ||
assertEquals("1234null6", flow.single()) | ||
} | ||
|
||
@Test | ||
fun testSevenParameters() = runBlocking { | ||
val flow = combine( | ||
flowOf("1"), | ||
flowOf(2), | ||
flowOf("3"), | ||
flowOf(4.toByte()), | ||
flowOf(null), | ||
flowOf("6"), | ||
flowOf(7) | ||
) { a, b, c, d, e, f, g -> | ||
a + b + c + d + e + f + g | ||
} | ||
assertEquals("1234null67", flow.single()) | ||
} | ||
|
||
@Test | ||
fun testEightParameters() = runBlocking { | ||
val flow = combine( | ||
flowOf("1"), | ||
flowOf(2), | ||
flowOf("3"), | ||
flowOf(4.toByte()), | ||
flowOf(null), | ||
flowOf("6"), | ||
flowOf(7), | ||
flowOf("8") | ||
) { a, b, c, d, e, f, g, h -> | ||
a + b + c + d + e + f + g + h | ||
} | ||
assertEquals("1234null678", flow.single()) | ||
} | ||
|
||
@Test | ||
fun testNineParameters() = runBlocking { | ||
val flow = combine( | ||
flowOf("1"), | ||
flowOf(2), | ||
flowOf("3"), | ||
flowOf(4.toByte()), | ||
flowOf(null), | ||
flowOf("6"), | ||
flowOf(7), | ||
flowOf("8"), | ||
flowOf(9.toByte()) | ||
) { a, b, c, d, e, f, g, h, i -> | ||
a + b + c + d + e + f + g + h + i | ||
} | ||
assertEquals("1234null6789", flow.single()) | ||
} | ||
|
||
@Test | ||
fun testTenParameters() = runBlocking { | ||
val flow = combine( | ||
flowOf("1"), | ||
flowOf(2), | ||
flowOf("3"), | ||
flowOf(4.toByte()), | ||
flowOf(null), | ||
flowOf("6"), | ||
flowOf(7), | ||
flowOf("8"), | ||
flowOf(9.toByte()), | ||
flowOf(null) | ||
) { a, b, c, d, e, f, g, h, i, j -> | ||
a + b + c + d + e + f + g + h + i + j | ||
} | ||
assertEquals("1234null6789null", flow.single()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ pluginManagement { | |
} | ||
|
||
include ':collections' | ||
include ':coroutines' |