Extensions: result.GetValueOrDefault() and result.GetValue() #1345
Replies: 1 comment 1 reply
-
If you want to get the value from a Fin<string> ma = FinSucc("thebestgin");
var r1 = ma.Match(Succ: x => $"Hello, {x}", Fail: e => e.ToString());
var r2 = ma.IfFail(e => e.ToString());
var r3 = ma.IfFail("default value"); If you definitely know the case, then you can cast: if(ma) // if in a `Succ` state
{
r4 = (string)ma;
}
if(!ma) // if in a `Fail` state
{
r5 = (Error)ma;
} In language-ext var r6 = ma switch
{
Fin.Succ<string>(var x) => x,
Fin.Fail<string>(var e) => e.ToString()
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am looking for an easy way to get the value of a result.
Have I possibly overlooked a possibility or is it missing?
I would like to use it like this:
Can be implemented very easily via an extension:
Beta Was this translation helpful? Give feedback.
All reactions