Gasan
11/06/2023, 7:35 PMSuccess
or Failure
type hierarchy or should I use some library for that?ascii
11/06/2023, 7:42 PMascii
11/06/2023, 7:42 PMGasan
11/06/2023, 7:44 PMGasan
11/06/2023, 7:45 PMGasan
11/06/2023, 7:46 PMResult
is for internal usage.Jacob
11/06/2023, 7:48 PMResult
class is not designed to represent domain-specific error conditions.Gasan
11/06/2023, 7:50 PMGasan
11/06/2023, 7:50 PMGasan
11/06/2023, 7:50 PMResult
type for every functionJacob
11/06/2023, 7:53 PMResult
class because:
if you want a generic response representing failure -> use null
else -> you need a domain specific response and the result class won’t help you anyways. Instead create your own domain specific resultPablichjenkov
11/06/2023, 7:53 PMYoussef Shoaib [MOD]
11/06/2023, 8:43 PMCLOVIS
11/06/2023, 11:13 PMGasan
11/06/2023, 11:33 PMGasan
11/06/2023, 11:42 PMsealed interface Result<T, R> {
class Success<T, R>(val value: T): Result<T, R>
class Failure<T, R>(val error: R): Result<T, R>
}
Sanjay Sheombar
11/07/2023, 2:18 AMJacob
11/07/2023, 2:40 AMStephan Schröder
11/07/2023, 8:17 AMCLOVIS
11/07/2023, 8:59 AMBut to be honest, It’s literally 4 lines of code:Yes, it is. And if that's all you need, great! But as soon as you start calling two functions which return
Result
and want to return a successful value if both are successful, etc, you will want map
, flatMap
, zip
… At that point, it quickly becomes worth using Arrow rather than rewrite everythingmitch
11/07/2023, 1:14 PMCLOVIS
11/07/2023, 1:23 PM