Skip to content

Commit

Permalink
Merge pull request #558 from mnissl/ResultTE_GetValueOrDefault
Browse files Browse the repository at this point in the history
Result<T, E>::GetValueOrDefault()
  • Loading branch information
vkhorikov authored Aug 20, 2024
2 parents 37e3142 + c09f1b8 commit 94ace21
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CSharpFunctionalExtensions/Result/ResultTE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ void ISerializable.GetObjectData(SerializationInfo info, StreamingContext contex
ResultCommonLogic.GetObjectData(this, info);
}

public T GetValueOrDefault(T defaultValue = default)
{
if (IsFailure)
return defaultValue;

return Value;
}

public static implicit operator Result<T, E>(T value)
{
if (value is IResult<T, E> result)
Expand Down

0 comments on commit 94ace21

Please sign in to comment.