Skip to content

Commit

Permalink
feat(monad): expose helper types for empty results (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
draekien committed Jun 19, 2024
1 parent 7a3a545 commit a2ed67a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1"/>
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1" PrivateAssets="All"/>
</ItemGroup>
</Project>
13 changes: 11 additions & 2 deletions src/FluentUtils.Monad/ErrorResultType.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
namespace FluentUtils.Monad;
using JetBrains.Annotations;

namespace FluentUtils.Monad;

/// <summary>
/// An <see cref="ErrorResultType{T}"/> for a result which would have returned an <see cref="Empty"/> value
/// </summary>
/// <param name="Error">The <see cref="Error"/></param>
public record ErrorResultType(Error Error) : ErrorResultType<Empty>(Error);

/// <summary>
/// The <see cref="ResultType{T}" /> variant that represents an error and containing an <see cref="Error" /> value
Expand All @@ -7,7 +15,8 @@
/// Do not access this record directly - invoke the <c>Unwrap</c> or <c>Match</c> extension methods instead
/// </remarks>
/// <typeparam name="T">The value type associated with it's <see cref="OkResultType{T}" /> counterpart</typeparam>
public sealed record ErrorResultType<T> : ResultType<T> where T : notnull
[PublicAPI]
public record ErrorResultType<T> : ResultType<T> where T : notnull
{
internal ErrorResultType(Error error)
{
Expand Down
13 changes: 11 additions & 2 deletions src/FluentUtils.Monad/OkResultType.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
namespace FluentUtils.Monad;
using JetBrains.Annotations;

namespace FluentUtils.Monad;

/// <summary>
/// An <see cref="OkResultType{T}" /> that contains an <see cref="Empty" /> value
/// </summary>
[PublicAPI]
public record OkResultType() : OkResultType<Empty>(new Empty());

/// <summary>
/// The <see cref="ResultType{T}" /> variant that represents a success and contains a value
Expand All @@ -7,7 +15,8 @@
/// Do not access this record directly - invoke the <c>Unwrap</c> or <c>Match</c> extension methods instead
/// </remarks>
/// <typeparam name="T">The value type</typeparam>
public sealed record OkResultType<T> : ResultType<T> where T : notnull
[PublicAPI]
public record OkResultType<T> : ResultType<T> where T : notnull
{
/// <summary>
/// Do not use directly
Expand Down
6 changes: 6 additions & 0 deletions src/FluentUtils.Monad/ResultType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

namespace FluentUtils.Monad;

/// <summary>
/// A <see cref="ResultType{T}" /> that contains an <see cref="Empty" /> value.
/// </summary>
[PublicAPI]
public abstract record ResultType : ResultType<Empty>;

/// <summary>
/// The result monad
/// </summary>
Expand Down

0 comments on commit a2ed67a

Please sign in to comment.