Skip to content

Commit 63b1e1a

Browse files
committed
Keep only one overload
1 parent 038c6b7 commit 63b1e1a

File tree

3 files changed

+9
-39
lines changed

3 files changed

+9
-39
lines changed

kotlinx-coroutines-core/api/kotlinx-coroutines-core.api

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,9 @@ public final class kotlinx/coroutines/channels/ChannelsKt {
820820
public static synthetic fun takeWhile$default (Lkotlinx/coroutines/channels/ReceiveChannel;Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lkotlinx/coroutines/channels/ReceiveChannel;
821821
public static final fun toChannel (Lkotlinx/coroutines/channels/ReceiveChannel;Lkotlinx/coroutines/channels/SendChannel;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
822822
public static final fun toCollection (Lkotlinx/coroutines/channels/ReceiveChannel;Ljava/util/Collection;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
823-
public static final fun toList (Lkotlinx/coroutines/channels/ReceiveChannel;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
823+
public static final fun toList (Lkotlinx/coroutines/channels/ReceiveChannel;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
824+
public static final synthetic fun toList (Lkotlinx/coroutines/channels/ReceiveChannel;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
825+
public static synthetic fun toList$default (Lkotlinx/coroutines/channels/ReceiveChannel;Ljava/util/List;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
824826
public static final fun toMap (Lkotlinx/coroutines/channels/ReceiveChannel;Ljava/util/Map;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
825827
public static final synthetic fun toMap (Lkotlinx/coroutines/channels/ReceiveChannel;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
826828
public static final synthetic fun toMutableList (Lkotlinx/coroutines/channels/ReceiveChannel;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;

kotlinx-coroutines-core/api/kotlinx-coroutines-core.klib.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,7 @@ final suspend fun kotlinx.coroutines/yield() // kotlinx.coroutines/yield|yield()
11421142
final suspend inline fun <#A: kotlin/Any?, #B: kotlin/Any?> (kotlinx.coroutines.flow/Flow<#A>).kotlinx.coroutines.flow/fold(#B, crossinline kotlin.coroutines/SuspendFunction2<#B, #A, #B>): #B // kotlinx.coroutines.flow/fold|fold@kotlinx.coroutines.flow.Flow<0:0>(0:1;kotlin.coroutines.SuspendFunction2<0:1,0:0,0:1>){0§<kotlin.Any?>;1§<kotlin.Any?>}[0]
11431143
final suspend inline fun <#A: kotlin/Any?> (kotlinx.coroutines.channels/BroadcastChannel<#A>).kotlinx.coroutines.channels/consumeEach(kotlin/Function1<#A, kotlin/Unit>) // kotlinx.coroutines.channels/consumeEach|consumeEach@kotlinx.coroutines.channels.BroadcastChannel<0:0>(kotlin.Function1<0:0,kotlin.Unit>){0§<kotlin.Any?>}[0]
11441144
final suspend inline fun <#A: kotlin/Any?> (kotlinx.coroutines.channels/ReceiveChannel<#A>).kotlinx.coroutines.channels/consumeEach(kotlin/Function1<#A, kotlin/Unit>) // kotlinx.coroutines.channels/consumeEach|consumeEach@kotlinx.coroutines.channels.ReceiveChannel<0:0>(kotlin.Function1<0:0,kotlin.Unit>){0§<kotlin.Any?>}[0]
1145+
final suspend inline fun <#A: kotlin/Any?> (kotlinx.coroutines.channels/ReceiveChannel<#A>).kotlinx.coroutines.channels/toList(kotlin.collections/MutableList<#A> = ...): kotlin.collections/List<#A> // kotlinx.coroutines.channels/toList|toList@kotlinx.coroutines.channels.ReceiveChannel<0:0>(kotlin.collections.MutableList<0:0>){0§<kotlin.Any?>}[0]
11451146
final suspend inline fun <#A: kotlin/Any?> (kotlinx.coroutines.flow/Flow<#A>).kotlinx.coroutines.flow/collect(crossinline kotlin.coroutines/SuspendFunction1<#A, kotlin/Unit>) // kotlinx.coroutines.flow/collect|collect@kotlinx.coroutines.flow.Flow<0:0>(kotlin.coroutines.SuspendFunction1<0:0,kotlin.Unit>){0§<kotlin.Any?>}[0]
11461147
final suspend inline fun <#A: kotlin/Any?> (kotlinx.coroutines.flow/Flow<#A>).kotlinx.coroutines.flow/collectIndexed(crossinline kotlin.coroutines/SuspendFunction2<kotlin/Int, #A, kotlin/Unit>) // kotlinx.coroutines.flow/collectIndexed|collectIndexed@kotlinx.coroutines.flow.Flow<0:0>(kotlin.coroutines.SuspendFunction2<kotlin.Int,0:0,kotlin.Unit>){0§<kotlin.Any?>}[0]
11471148
final suspend inline fun <#A: kotlin/Any?> (kotlinx.coroutines.flow/SharedFlow<#A>).kotlinx.coroutines.flow/count(): kotlin/Int // kotlinx.coroutines.flow/count|count@kotlinx.coroutines.flow.SharedFlow<0:0>(){0§<kotlin.Any?>}[0]

kotlinx-coroutines-core/common/src/channels/Channels.common.kt

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -161,41 +161,9 @@ public suspend inline fun <E> ReceiveChannel<E>.consumeEach(action: (E) -> Unit)
161161
for (e in this) action(e)
162162
}
163163

164-
/**
165-
* Returns a [List] containing all the elements sent to this channel, preserving their order.
166-
*
167-
* This function will attempt to receive elements and put them into the list until the channel is
168-
* [closed][SendChannel.close].
169-
* Calling [toList] on channels that are not eventually closed is always incorrect:
170-
* - It will suspend indefinitely if the channel is not closed, but no new elements arrive.
171-
* - If new elements do arrive and the channel is not eventually closed, [toList] will use more and more memory
172-
* until exhausting it.
173-
*
174-
* If the channel is [closed][SendChannel.close] with a cause, [toList] will rethrow that cause.
175-
*
176-
* The operation is _terminal_.
177-
* This function [consumes][ReceiveChannel.consume] all elements of the original [ReceiveChannel].
178-
*
179-
* Example:
180-
* ```
181-
* val values = listOf(1, 5, 2, 9, 3, 3, 1)
182-
* // start a new coroutine that creates a channel,
183-
* // sends elements to it, and closes it
184-
* // once the coroutine's body finishes
185-
* val channel = produce {
186-
* values.forEach { send(it) }
187-
* }
188-
* check(channel.toList() == values)
189-
* ```
190-
*/
191-
public suspend fun <E> ReceiveChannel<E>.toList(): List<E> = buildList {
192-
consumeEach {
193-
add(it)
194-
}
195-
}
196-
197164
/**
198165
* Consumes the elements of this channel into the given [destination] mutable list.
166+
* If none is provided, a new [ArrayList] will be created.
199167
*
200168
* This function will attempt to receive elements and put them into the list until the channel is
201169
* [closed][SendChannel.close].
@@ -225,11 +193,8 @@ public suspend fun <E> ReceiveChannel<E>.toList(): List<E> = buildList {
225193
* check(destination == values)
226194
* ```
227195
*/
228-
public suspend inline fun <T> ReceiveChannel<T>.toList(destination: MutableList<T>) {
229-
consumeEach {
230-
destination.add(it)
231-
}
232-
}
196+
public suspend inline fun <T> ReceiveChannel<T>.toList(destination: MutableList<T> = ArrayList()): List<T> =
197+
consumeEach(destination::add).let { destination }
233198

234199
@PublishedApi
235200
internal fun ReceiveChannel<*>.cancelConsumed(cause: Throwable?) {
@@ -238,3 +203,5 @@ internal fun ReceiveChannel<*>.cancelConsumed(cause: Throwable?) {
238203
})
239204
}
240205

206+
@Deprecated("Preserving binary compatibility, was stable", level = DeprecationLevel.HIDDEN)
207+
public suspend fun <T> ReceiveChannel<T>.toList(): List<T> = toList(ArrayList())

0 commit comments

Comments
 (0)