File tree 2 files changed +5
-1
lines changed
kotlinx-coroutines-core/common
2 files changed +5
-1
lines changed Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ public suspend fun <T> Flow<T>.single(): T {
71
71
* The terminal operator, that awaits for one and only one value to be published.
72
72
* Throws [IllegalStateException] for flow that contains more than one element.
73
73
*/
74
- public suspend fun <T : Any > Flow<T>.singleOrNull (): T ? {
74
+ public suspend fun <T > Flow<T>.singleOrNull (): T ? {
75
75
var result: T ? = null
76
76
collect { value ->
77
77
if (result != null ) error(" Expected only one element" )
Original file line number Diff line number Diff line change @@ -61,6 +61,10 @@ class SingleTest : TestBase() {
61
61
assertEquals(1 , flowOf<Int ?>(1 ).single())
62
62
assertNull(flowOf<Int ?>(null ).single())
63
63
assertFailsWith<NoSuchElementException > { flowOf<Int ?>().single() }
64
+
65
+ assertEquals(1 , flowOf<Int ?>(1 ).singleOrNull())
66
+ assertNull(flowOf<Int ?>(null ).singleOrNull())
67
+ assertFailsWith<NoSuchElementException > { flowOf<Int ?>().singleOrNull() }
64
68
}
65
69
66
70
@Test
You can’t perform that action at this time.
0 commit comments