I tried defining my own Collectors, but I get: &gt...
# arrow
d
I tried defining my own Collectors, but I get:
Overload resolution ambiguity. All these functions match.
public fun <A, R, S, V> zip(x: Collector<TypeVariable(A), TypeVariable(R)> /* = CollectorI<*, TypeVariable(A), TypeVariable(R)> /, y: Collector<TypeVariable(A), TypeVariable(S)> / = CollectorI<*, TypeVariable(A), TypeVariable(S)> /, combine: suspend (TypeVariable(R), TypeVariable(S)) → TypeVariable(V)): Collector<TypeVariable(A), TypeVariable(V)> / = CollectorI<*, TypeVariable(A), TypeVariable(V)> */ defined in arrow. collectors
public fun <A, R, S, V> zip(x: NonSuspendCollector<TypeVariable(A), TypeVariable(R)> /* = NonSuspendCollectorI<*, TypeVariable(A), TypeVariable(R)> /, y: NonSuspendCollector<TypeVariable(A), TypeVariable(S)> / = NonSuspendCollectorI<*, TypeVariable(A), TypeVariable(S)> /, combine: (TypeVariable(R), TypeVariable(S)) → TypeVariable(V)): NonSuspendCollector<TypeVariable(A), TypeVariable(V)> / = NonSuspendCollectorI<*, TypeVariable(A), TypeVariable(V)> */ defined in arrow. collectors
when using them... how can I solve this? I used
Collector.nonSuspendOf
Maybe it's because only the return type is different and NonSuspendCollector derives from Collector... shouldn't the function name be nonSuspendZip because of this?
I had to declare my own function in my project for this to work:
Copy code
fun <A, R, S, T, V> zipNonSuspend(
    x: NonSuspendCollector<A, R>,
    y: NonSuspendCollector<A, S>,
    z: NonSuspendCollector<A, T>,
    combine: (R, S, T) -> V,
): NonSuspendCollector<A, V> = x.zip(y).zipNonSuspend(z) { (a, b), c -> combine(a, b, c) }
a
interestig... could you send a snippet of the code? maybe there's some overload problems I'm not aware of
d
Copy code
fun <T> filterCollector(filter: (T) -> Boolean) = Collector.nonSuspendOf(
    supply = { mutableListOf<T>() },
    accumulate = { acc, t: T -> if (filter(t)) acc.add(t) },
    finish = { it }
)

val list = listOf(1, 2, 3)

val coll = zip(filterCollector<Int> { it == 1 }, filterCollector<Int> { it != 1 }, ::Pair)
zip is red in that case and has the previous error in the bubble
Was this fixed in 2.0 @Alejandro Serrano.Mena?
a
I don't think so, I still need to check