Skip to content

Commit

Permalink
Release v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
domn1995 committed Sep 22, 2022
1 parent 5dc15a4 commit 4fd2354
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
44 changes: 44 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,50 @@ var output = result.Match(
Console.WriteLine(output); // "Cannot divide by zero!"
```

## Async Match Support

Dunet generates a `MatchAsync()` extension method for all `Task<T>` and `ValueTask<T>` where `T` is a union type. For example:

```cs
// Choice.cs
using Dunet;

namespace Core;

// 1. Define a union type within a namespace.
[Union]
partial record Choice
{
partial record Yes;
partial record No(string Reason);
}
```

```cs
// Program.cs
using Core;

// 2. Define async methods like you would for any other type.
static async Task<Choice> AskAsync()
{
// Simulating network call.
await Task.Delay(1000);

// 3. Return unions from async methods as you'd return any other type.
return new No("because I don't wanna!");
}

// 4. Asynchronously match any union `Task` or `ValueTask`.
var response = await AskAsync().MatchAsync(yes => "Yes!!!", no => $"No, {no.Reason}");

Console.WriteLine(response); // Prints "No, because I don't wanna!" after 1 second.
```

> **Note**:
> `MatchAsync()` can only be generated for namespace unions.
## Nested Union Support

To declare a union nested within a class or record, the class or record must be `partial`. For example:
Expand Down
9 changes: 5 additions & 4 deletions src/Dunet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
<PackageReadmeFile>Readme.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/domn1995/dunet</RepositoryUrl>
<PackageTags>source; generator; discriminated; union; functional; tagged;</PackageTags>
<AssemblyVersion>1.2.0</AssemblyVersion>
<FileVersion>1.2.0</FileVersion>
<AssemblyVersion>1.3.0</AssemblyVersion>
<FileVersion>1.3.0</FileVersion>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReleaseNotes>1.2.0 - Support nested union declarations.
<PackageReleaseNotes>1.3.0 - Async match methods.
1.2.0 - Support nested union declarations.
1.1.0 - Add implicit conversions for union members.
1.0.2 - Support multiple unions with the same name.
1.0.1 - Configure Dunet as development dependency.
Expand All @@ -36,7 +37,7 @@
<RepositoryType>git</RepositoryType>
<PackageIcon>favicon.png</PackageIcon>
<SignAssembly>False</SignAssembly>
<Version>1.2.0</Version>
<Version>1.3.0</Version>
<NeutralLanguage>en</NeutralLanguage>
<DevelopmentDependency>true</DevelopmentDependency>
<NoWarn>$(NoWarn);NU5128</NoWarn>
Expand Down

0 comments on commit 4fd2354

Please sign in to comment.