artem_zin
09/24/2018, 4:34 AMResult (also known as SuccessOrError) type before 1.3 release?
I think it can be improved and you might want it to be improved for the future of language, I’m writing a KEEP but it takes a long time so I wanted to reach out so you know it’s comingartem_zin
09/24/2018, 4:37 AMResult cases as public sealed class subtypes (can be as optimized as inline class with benefits of SmartCasts and more)
- Allow a failure case to store anything instead of just Throwable
- Change names of Result cases to more concise ones (Ok and Er)artem_zin
09/24/2018, 4:37 AMResult type is placed directly in kotlin
package, and now that it’s [renamed](#159) to Result from SuccessOrFailure,
it’s becoming clear that Result type might have a wide adoption
outside of code generated by compiler for coroutines in
future.
That’s why it’s important to address several aspects of its API.artem_zin
09/24/2018, 4:38 AMelizarov
09/24/2018, 4:56 AMartem_zin
09/24/2018, 4:57 AMartem_zin
09/24/2018, 4:58 AMartem_zin
09/24/2018, 4:59 AMResult is a very important type in many languages, rushing its design will be a costly mistake…gildor
09/24/2018, 5:16 AMResult<Foo, Throwable> everywhere is tediouselizarov
09/24/2018, 5:18 AMgildor
09/24/2018, 5:18 AMdeviant
09/24/2018, 9:03 AMkotlin.Result as a function return type?Andreas Sinz
09/24/2018, 9:14 AMthemishkun
09/24/2018, 10:38 AMflatMapgildor
09/24/2018, 10:58 AM-Xallow-result-return-type
But I found some issue, cannot reproduce on minimal example yetgildor
09/24/2018, 11:04 AM(T) -> R, to have flatMap semantics that allows you chain multiple Results lambda should be (T) -> Result<R>
So runCatching is just a "safe" version of mapthemishkun
09/24/2018, 11:09 AMmapCatching is effectively the same as a flatMap, but more of imperative stylethemishkun
09/24/2018, 11:17 AMResult. For me Result<T> looks like specialised Either<T, Throwable> and so the T? looks like Either<T, Nothing>. Any chances that it would be allowed to overload safe-call operators? That would allow other Either patterns like chained validation to be used with this concise syntax.gildor
09/24/2018, 2:16 PMelizarov
09/24/2018, 3:22 PMResult into a specialized Either, because the names of the components types and operators that Either supports make no sense for Result. Of cause, you can learn that “left” is a failure, while “right” is a success, but why ruin the readability of your code if you can simply use a type that is tailed to its use with the names that fit? The code will be oh so much more readable.eddie
09/24/2018, 3:25 PMkotlin.experimental as well. I already use a type named Result through my app that has better semantics (in my use cases, at least; for example, representing it as a sealed class hierarchy as Artem described). It does indeed feel like Result as-is has been rushed. I think preferring the optimization that inline class brings over useful semantics is a mistake. (As the KEEP says, if sealed + inline class support comes in the future it can be added later, but I’d prefer to have sealed now instead of inline.)gildor
09/24/2018, 3:27 PMgildor
09/24/2018, 3:28 PMeddie
09/24/2018, 3:28 PMkotlin namespace, especially if it can’t be used in regular signatures out of the gateeddie
09/24/2018, 3:29 PMelizarov
09/24/2018, 3:32 PMResult no problem. kotlin automatically imported names have lower priority in resolution than project-specific names.elizarov
09/24/2018, 3:33 PMgildor
09/24/2018, 3:34 PMelizarov
09/24/2018, 3:34 PMeddie
09/24/2018, 3:35 PMelizarov
09/24/2018, 3:35 PMthemishkun
09/24/2018, 3:48 PMelizarov
09/24/2018, 3:52 PMFleshgrinder
09/24/2018, 5:30 PMOk and Er? Not Err? Er is definitely not proper English.themishkun
09/24/2018, 8:13 PMOk and Er both have 2 symbols, so they would align nicely in when-expressionFleshgrinder
09/24/2018, 8:35 PMwhen (result) {
Ok -> // ...
Err -> // ...
}
Problem solved. 😉Fleshgrinder
09/24/2018, 8:39 PMartem_zin
09/24/2018, 9:07 PMSuccess and Failure are also aligned horizontally as they're each 7 symbols
However it is painful in Rust (I code a bit in it), Ok and Err don't align automaticallyFleshgrinder
09/24/2018, 9:12 PMSuccess and Failure sound good to me. As I said, I don't really share this sentiment as correctness is more important to me than solving special cases. Anyone who wants his `when`/`match` to align should, well, align them.jdemeulenaere
09/24/2018, 9:12 PMelizarov
09/24/2018, 9:59 PM