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
Sometimes you just need an exception, even if avoiding them is a goal of this library. Examples include situations where you are defining a custom type that has Parse() and TryParse() methods that both point to a common method returning Result<T>.
Currently it is possible to accomplish something similar to the proposed OrThrow() function by doing the following:
publicstaticFooTryParse(stringvalue){Result<Foo>parseResult=TryParseResult(value);returnparseResult.MapOrElse(
it =>it,(error,_)=>thrownewException(...));}
This feels like an abuse of the Map part of the MapOrElse() pattern. Returning itself is not the intended use.
So I'd like to propose the following, which does exactly the same thing as above but with better semantics:
Sometimes you just need an exception, even if avoiding them is a goal of this library. Examples include situations where you are defining a custom type that has
Parse()
andTryParse()
methods that both point to a common method returningResult<T>
.Currently it is possible to accomplish something similar to the proposed
OrThrow()
function by doing the following:This feels like an abuse of the
Map
part of theMapOrElse()
pattern. Returning itself is not the intended use.So I'd like to propose the following, which does exactly the same thing as above but with better semantics:
Example usage:
The text was updated successfully, but these errors were encountered: