Flow.take(0) should be an empty Flow, in the documentation:
But
Makes sense to me. The code could use an early return here:
require(count >= 0) { "Requested element count $count should be positive" }
if(count==0) return emptyFlow()
Thanks, I will fix the docs.
The problem with this fast-path is that one may expect that even for take(0) an original flow is started (=> start side-effects are observable), but with this change take(n) unexpectedly starts to behave differently in the terms of the source flow side-effects depending on the n value.
But other users may expect that flow is not started if n == 0 :)
I'd rather prohibit zero at all unless there is a serious demand on it.
Most helpful comment
Thanks, I will fix the docs.
The problem with this fast-path is that one may expect that even for
take(0)an original flow is started (=> start side-effects are observable), but with this changetake(n)unexpectedly starts to behave differently in the terms of the source flow side-effects depending on thenvalue.But other users may expect that flow is not started if
n == 0:)I'd rather prohibit zero at all unless there is a serious demand on it.