You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I understand the concern - currently the ways in which you can access the exceptional value are rather limited, which is something I will certainly look into improving in a future release.
For now, I suggest you simply introduce your own set of extension methods to suit your needs, e.g. something like:
publicstaticclass OptionExceptionExtensions
{publicstatic TException ExceptionOr<TValue,TException>(thisOption<TValue,TException>option,Func<TException>alternativeFactory)=>
option.Match(_ => alternativeFactory(),exception => exception);publicstatic TException ExceptionOr<TValue,TException>(thisOption<TValue,TException>option,Func<TValue,TException>alternativeFactory)=>
option.Match(alternativeFactory,exception => exception);}// And use it like:
option.ExceptionOr(()=>thrownew InvalidOperationException("Unexpected value"));
option.ExceptionOr(value =>thrownew InvalidOperationException($"Unexpected value: {value}");
I will consider adding similar functionality in a future release, but introducing your own set of additional utility methods is probably the easiest way to get the functionality today.
There are certain use cases that require access to that member
just as the Unsafe namespace allows access to Value, same should be with Exception
The text was updated successfully, but these errors were encountered: