|
|
|
|
|
by BoorishBears
2022 days ago
|
|
Maybe I'm missing something but why does this not work with Java? Is it the fact you would put your xs.map call in a mapper or something? Because I know for sure you can do it in Kotlin: https://github.com/michaelbull/kotlin-result But I don't see reified generics as a requirement for what you describe, and that's the main Kotlin-only feature I see being used |
|
You can emulate Rust's approach with Java, by creating what is essentially a sum type like Result. You'd have to enforce that any access to its content must also handle the error case, and I don't really know how to do that generally. There are various hacks, like having a bespoke sum type for that particular operation that twrows a particular exception on access to its content. But that gets really old, really fast.