Ah, I was looking at autocomplete methods on the nullable variable. Maybe that is not allowed to define?
Addet it to SO.
y
Youssef Shoaib [MOD]
12/24/2021, 12:48 PM
It's probably completely valid to define it, but I'm guessing it'll pollute the autocomplete for all Kotlin variables, since anything defined on
Any?
also accepts
Any
t
than_
12/24/2021, 12:51 PM
Not just pollute, there's gonna be no way to distinguish which function to call
Copy code
val e1: Either<A,B>
val e2: Either<A,B>
e1.zip(e2, ::Pair)
y
Youssef Shoaib [MOD]
12/24/2021, 12:53 PM
Isn't it the case that extension funs are resolved based on the most specific receiver type?, so actually that case should work, but it'll be confusing if you have a nullable either
t
than_
12/24/2021, 1:01 PM
try running this:
Copy code
import arrow.core.Either
import arrow.core.zip
inline fun <A,B, R> A?.zip(b: B?, f: (A, B) -> R): R? =
this?.let{ aa -> b?.let{bb -> f(aa,bb)}}
val e1 = Either.Right(1)
val e2 = Either.Left(Unit)
null.zip(2, ::Pair).let(::println)
e1.zip(e2, ::Pair).let(::println)
it's gonna print
Copy code
null // as expected
(Either.Right(1), Either.Left(kotlin.Unit)) // yikes :D