I just encountered a problem with `combine` method...
# coroutines
a
I just encountered a problem with
combine
method. For some reason it accepts
Array
instead of
List
and has reified type. It does not make a lot of sense since the type is not used everywhere. I have a place where reification is not possible and it looks really Ugly:
Copy code
override val valueFlow: Flow<R> = combine<Any, R>(states.map { it.valueFlow } as Iterable<Flow<Any>>){ array: Array<Any>->
        mapper(array.asList() as List<T>)
    }
Is there a better way to do that?
e
it's not possible to construct an
Array<T>
without
reified T
, and
combine
internally reuses the array across calls for efficiency in internal users, and creates a new one for safety of public users but maintains the same api
you only need the cast in one place though, everything else can be done through type inference
Copy code
override val valueFlow: Flow<R> = combine(states.map { it.valueFlow }) { array: Array<Any?> ->
        mapper(array.asList() as List<T>)
    }
a
@ephemient You are correct, I can remove it if I use Any? instead of Any. Still, it does not make sense that type is required even if it is not used.
e
it is used. for historical Java reasons,
Array<T>
is special and (unlike generics) requires reification
a
I know why it requires reification. And I looked into the code. The problem is that Array should not be used at all outside interop. It does not make any sense in Kotlin (number arrays do for performance, but not
Array
).