Andrea Fabris
04/12/2024, 11:21 AMfun mainFun(): Either<A, B>
where A is a sealed interface. I then call this within another function fun caller(): Either<A, B?>
whose goal is to check if the called mainFun
returns left and if so, depending on the type of the left, return B? or A. It always return B if mainFun
returns B.
Currently I’m using fold like the below, so I’m wondering if there’s a better way to do that?
return mainFun().fold({if(it == SpecialSealedImpl} null.right else it.left) { it.right }
simon.vergauwen
04/12/2024, 11:41 AMrecover
function.
mainFun().recover { if(it == SpecialSealedImpl} null else raise(it) }
simon.vergauwen
04/12/2024, 11:41 AMnull
or raise
a different error, in this case the same one.Andrea Fabris
04/12/2024, 11:44 AMAndrea Fabris
04/12/2024, 11:44 AMsimon.vergauwen
04/12/2024, 11:44 AM