File tree Expand file tree Collapse file tree 2 files changed +5
-4
lines changed
kotlinx-coroutines-core/common Expand file tree Collapse file tree 2 files changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -50,8 +50,7 @@ public fun <T> Flow<T>.dropWhile(predicate: suspend (T) -> Boolean): Flow<T> = f
50
50
*/
51
51
@FlowPreview
52
52
public fun <T > Flow<T>.take (count : Int ): Flow <T > {
53
- require(count >= 0 ) { " Requested element count $count is less than zero." }
54
- if (count == 0 ) return emptyFlow()
53
+ require(count > 0 ) { " Requested element count $count should be positive" }
55
54
return flow {
56
55
var consumed = 0
57
56
try {
Original file line number Diff line number Diff line change @@ -28,13 +28,15 @@ class TakeTest : TestBase() {
28
28
}
29
29
30
30
@Test
31
- fun testNonPositiveValues () = runTest {
31
+ fun testNonPositiveValues () {
32
32
val flow = flowOf(1 )
33
33
assertFailsWith<IllegalArgumentException > {
34
34
flow.take(- 1 )
35
35
}
36
36
37
- assertNull(flow.take(0 ).singleOrNull())
37
+ assertFailsWith<IllegalArgumentException > {
38
+ flow.take(0 )
39
+ }
38
40
}
39
41
40
42
@Test
You can’t perform that action at this time.
0 commit comments