Skip to content

Commit

Permalink
add new implicit operator
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiasnordqvist committed Sep 17, 2024
1 parent b79e137 commit 0827c36
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.5.7</Version>
<Version>1.5.8</Version>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>
Expand Down
9 changes: 9 additions & 0 deletions Results/DotNetThoughts.Results/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ public readonly record struct Result<T>
[Pure]
public static implicit operator Result<Unit>(Result<T> result) => result.ToUnitResult();

/// <summary>
/// This implicit operator takes a Result of type T and returns a Result of type Unit by throwing away the value, preserving only success or failure, along with errors.
/// This UnitResult is then wrapped in a completed Task.
/// It is the same as calling Task.FromResult(result.ToUnitResult()).
/// </summary>
/// <param name="result"></param>
[Pure]
public static implicit operator Task<Result<Unit>>(Result<T> result) => Task.FromResult(result.ToUnitResult());

/// <summary>
/// Creates a successful Result of type T.
/// </summary>
Expand Down

0 comments on commit 0827c36

Please sign in to comment.