Does it Flow extensions `single` is equivalent to ...
# flow
m
Does it Flow extensions
single
is equivalent to
first
? There’s seems a weird issue in my part. When using
single
it returns
null
, but exist otherwise with
first
n
single
will wait for the
Flow
to finish in the successful case and throw if there was more than just the one item unlike
first
.
today i learned 1
🙏 1
e
it doesn't wait for the flow to finish, it just waits to confirm whether the flow has a single element or not. e.g.
Copy code
flow {
    emit(1)
    emit(2)
    delay(1_000_000)
}.single()
doesn't wait for the delay because it can throw as soon as 2 is emitted
K 1
today i learned 1
✍️ 1
🙏 1
this is the same as the stdlib
single
function on Iterable and Sequence
Copy code
sequence {
    yield(1)
    yield(2)
    println("unreachable")
}.single()
n
Thanks for the clarification. I updated my comment above (the italics part) to be clearer.