Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove default params to flow extensions #3489

Merged
merged 2 commits into from Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -22,7 +22,6 @@ import app.cash.sqldelight.Query
import app.cash.sqldelight.async.coroutines.awaitAsList
import app.cash.sqldelight.async.coroutines.awaitAsOne
import app.cash.sqldelight.async.coroutines.awaitAsOneOrNull
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.Channel.Factory.CONFLATED
import kotlinx.coroutines.flow.Flow
Expand Down Expand Up @@ -58,7 +57,7 @@ fun <T : Any> Query<T>.asFlow(): Flow<Query<T>> = flow {

@JvmOverloads
fun <T : Any> Flow<Query<T>>.mapToOne(
context: CoroutineContext = Dispatchers.Default,
context: CoroutineContext,
): Flow<T> = map {
withContext(context) {
it.awaitAsOne()
Expand All @@ -68,7 +67,7 @@ fun <T : Any> Flow<Query<T>>.mapToOne(
@JvmOverloads
fun <T : Any> Flow<Query<T>>.mapToOneOrDefault(
defaultValue: T,
context: CoroutineContext = Dispatchers.Default,
context: CoroutineContext,
): Flow<T> = map {
withContext(context) {
it.awaitAsOneOrNull() ?: defaultValue
Expand All @@ -77,7 +76,7 @@ fun <T : Any> Flow<Query<T>>.mapToOneOrDefault(

@JvmOverloads
fun <T : Any> Flow<Query<T>>.mapToOneOrNull(
context: CoroutineContext = Dispatchers.Default,
context: CoroutineContext,
): Flow<T?> = map {
withContext(context) {
it.awaitAsOneOrNull()
Expand All @@ -86,7 +85,7 @@ fun <T : Any> Flow<Query<T>>.mapToOneOrNull(

@JvmOverloads
fun <T : Any> Flow<Query<T>>.mapToOneNotNull(
context: CoroutineContext = Dispatchers.Default,
context: CoroutineContext,
): Flow<T> = mapNotNull {
withContext(context) {
it.awaitAsOneOrNull()
Expand All @@ -95,7 +94,7 @@ fun <T : Any> Flow<Query<T>>.mapToOneNotNull(

@JvmOverloads
fun <T : Any> Flow<Query<T>>.mapToList(
context: CoroutineContext = Dispatchers.Default,
context: CoroutineContext,
): Flow<List<T>> = map {
withContext(context) {
it.awaitAsList()
Expand Down
Expand Up @@ -6,6 +6,7 @@ import app.cash.sqldelight.coroutines.Employee.Companion.USERNAME
import app.cash.sqldelight.coroutines.TestDb.Companion.TABLE_EMPLOYEE
import app.cash.turbine.test
import kotlinx.coroutines.CoroutineStart.UNDISPATCHED
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.yield
import kotlin.test.Test
Expand Down Expand Up @@ -103,7 +104,7 @@ class QueryAsFlowTest : DbTest {
@Test fun queryCanBeCollectedMoreThanOnce() = runTest { db ->
val flow = db.createQuery(TABLE_EMPLOYEE, "$SELECT_EMPLOYEES WHERE $USERNAME = 'john'", MAPPER)
.asFlow()
.mapToOneNotNull()
.mapToOneNotNull(Dispatchers.Default)

val employee = Employee("john", "John Johnson")

Expand Down