Curious to know why `either.eager {...}` seems to ...
# arrow
s
Curious to know why
either.eager {...}
seems to need explicit type arguments, while
either {...}
does not. e.g.
Copy code
fun fn(): Either<Throwable, Boolean> = TODO()

suspend fun example() {
    either.eager<Throwable, Boolean> {
        val a = !fn()
        val b = !fn()
        a && b
    }
    either {
        val a = !fn()
        val b = !fn()
        a && b
    }
}
without the type arguments, it fails to infer the type of
E
👀 1
k
hi @Scott Christopher, sorry for taking this long… I run the test on the
either
and
either.eager
with
KOTLIN_VERSION=1.4.10
I would assume this is a problem with type inference but didn’t tested on previous versions of Kotlin yet. Also what you found is not just that but the error highlighting does not indicate missing type with
invoke
functions with lambdas but neither of the scopes were able to infer the
E
value for me. The test above shows that IDEA indicates missing type inference with lamda syntaxt but calling explicitly invoke does show an error.
Sadly I have no recollection how this was worked on a previous compiler. If you explicitly apply the types it should work correctly.
s
No need to apologise for your reply 🙂 That aligns with what we're seeing too, so perhaps it's more of an IntelliJ quirk than the compiler's type inference. Either way it was more of a curiosity than anything that we needed solved.
k
It was definitely a good point to raise, I would also expect the compiler to infer the type for both left and right values.
if the implementation moves to suspension, I would expect this to be resolved.🤞 but I think we need someone with more experience to answer that 😅