`out E` is where I started. See first snippet
i
out E
is where I started. See first snippet
🧵 1
oh your code compiles
the fix is then to add
E
as generic parameter to the function?
is that correct? It's supposed to be the same
E
from the instance
s
It is removing the methods outside the sealed class and make them extension functions.
E.g. this all works as well, calling/using your Result class:
Copy code
fun testing() {
    val x = Result.Ok(5)
    val y = x.map { it * 2 }

    val z: Result<Int,String> = Result.Err("Error")
    val y2 = z.map { it + 4 }
    val y3 = z.mapError { it.length }

    val q: Result<String, Throwable> = x.flatMap { Result.Ok("$it") }
}
BTW: I updated the code-snippet a little bit to make it create less objects https://kotlinlang.slack.com/archives/C0922A726/p1558032372083600
i
awesome, will use this. Thank you!
j
@iex You could also copy the stdlib Result and make it inline class
Only the Err needs to be boxed
Also, guessing by names you’re a rustacean? 🙂
i
no 😄
j
i
thanks 👍
j
inline
allthethings