Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 80eefdf4 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Further simplification of collectValues." into udc-dev am: 52339c91 am: 25c2d8d9

parents 36438ff6 25c2d8d9
Loading
Loading
Loading
Loading
+2 −12
Original line number Original line Diff line number Diff line
@@ -69,10 +69,10 @@ fun <T> TestScope.collectValues(
    flow: Flow<T>,
    flow: Flow<T>,
    context: CoroutineContext = EmptyCoroutineContext,
    context: CoroutineContext = EmptyCoroutineContext,
    start: CoroutineStart = CoroutineStart.DEFAULT,
    start: CoroutineStart = CoroutineStart.DEFAULT,
): FlowValues<T> {
): FlowValue<List<T>> {
    val values = mutableListOf<T>()
    val values = mutableListOf<T>()
    backgroundScope.launch(context, start) { flow.collect(values::add) }
    backgroundScope.launch(context, start) { flow.collect(values::add) }
    return FlowValuesImpl {
    return FlowValueImpl {
        runCurrent()
        runCurrent()
        values.toList()
        values.toList()
    }
    }
@@ -83,17 +83,7 @@ interface FlowValue<T> : ReadOnlyProperty<Any?, T> {
    operator fun invoke(): T
    operator fun invoke(): T
}
}


/** @see collectValues */
interface FlowValues<T> : ReadOnlyProperty<Any?, List<T>> {
    operator fun invoke(): List<T>
}

private class FlowValueImpl<T>(private val block: () -> T) : FlowValue<T> {
private class FlowValueImpl<T>(private val block: () -> T) : FlowValue<T> {
    override operator fun invoke(): T = block()
    override operator fun invoke(): T = block()
    override fun getValue(thisRef: Any?, property: KProperty<*>): T = invoke()
    override fun getValue(thisRef: Any?, property: KProperty<*>): T = invoke()
}
}

private class FlowValuesImpl<T>(private val block: () -> List<T>) : FlowValues<T> {
    override operator fun invoke(): List<T> = block()
    override fun getValue(thisRef: Any?, property: KProperty<*>): List<T> = invoke()
}