https://kotlinlang.org logo
#coroutines
Title
# coroutines
j

jimn

12/05/2019, 4:39 PM
how does one do flow1.collect and flow2.collect in unison to combine right and left halves?
d

diesieben07

12/05/2019, 4:40 PM
flow1.zip(flow2) { a, b -> value }
?
j

jimn

12/05/2019, 4:49 PM
the example delays creep me out a bit, but ok, i see that's viable, thanks!
d

diesieben07

12/05/2019, 4:51 PM
Either
zip
or
combine
, depending on your needs.
j

jimn

12/05/2019, 4:53 PM
the flows are Array<*>, they don't like plus ....
🤔 1
previsouly, before the zip, these were promoted to list.
Copy code
Error:(333, 48) Kotlin: Cannot choose among the following candidates without completing type inference: 
public operator fun <T> Array<Any?>.plus(element: Any?): Array<Any?> defined in kotlin.collections
public operator fun <T> Array<Any?>.plus(elements: Array<out Any?>): Array<Any?> defined in kotlin.collections
is this a bug or a designed safety feature?
d

diesieben07

12/05/2019, 4:58 PM
You should specify the type on
a
and
b
explicitly to help the compiler here
j

jimn

12/05/2019, 5:01 PM
i have been wrestling with this for days, the only thing that gets me out of it is promoting to List<Any?>
im thinking maybe just bake in system.arraycopy, because elegant
a

alllex

12/05/2019, 7:34 PM
@jimn You can specify exactly which of the
plus
implementations you need. In this case it is
a.plus(elements = b)
j

jimn

12/05/2019, 11:25 PM
SO has a thing, the spread operator is way cheaper. seems to be