You have to handle the left case as an Either
value can be left type L
or right type R
.
If you want to throw an exception when result is an Error
you can use this:
var toReturn = result.IfLeft(err => throw err.ToException());
But you should avoid this. It's better to stay within Either
using Map
/Select
and pass any errors to the calling method:
var errorOrFunctionResult = result.Map(x => someFunction(x));
If you want to supply a fallback value in case of an error:
var toReturn = result.IfLeft((100, 0))
Basically Either
is similar to Option
regarding usage and you can find a good introduction here: https://github.com/louthy/language-ext/#option