What is idiomatic way to work with Either
's in Scala? For example when using Option
I can use orElse
method to get next optional value if current is None
. But how to work with Either
in same way? I didn't find method like orElse
to chain Either's (and I understand that it's not good idea to have such method because we lost the Left
value)
Edit: In fact I have a sequence of if-elseif-elseif-else
expressions each returning Right
or Left
. And I want to refactor my code so it become "more functional". So I can replace it with firstOption orElse secondOption orElse...
if it were Option
, but how to use here Either
?