|
|
|
|
|
by adimitrov
2020 days ago
|
|
Try to stick a function that may fail into a higher order function. The best example would be .map on streams/collections. You can only do it with unchecked exceptions in Java. In Rust, you can transparently do it with iterators and the result type. So given xs: [A] and f: A -> Result<A, E>, it is trivial to typesafely get Result<[A], E> by xs.map(f) where map: forall T. [T] -> (T -> S) -> [S]. This is outright impossible with Java. You have to circumvent the type system, or emulate Rust's approach. |
|
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