Skip to content

Commit

Permalink
Release v1.10.0 (#177)
Browse files Browse the repository at this point in the history
Rev to v1.10.0 and update readme.
  • Loading branch information
domn1995 authored Nov 2, 2023
1 parent 8eed569 commit 70d0624
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
35 changes: 34 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,42 @@ public static async Task<HttpResponse> CreateUserAsync(
}
```

## Unwrapping

To bypass exhaustive matching and access a variant directly, use the variant-specific `Unwrap` methods.

This can be useful if you're sure of the underlying value or if you don't care about a potential exception at runtime.

```cs
using Dunet;

[Union]
partial record Option<T>
{
partial record Some(T Value);
partial record None;
}
```

```cs
Option<double> option1 = new Option<double>.Some(3.14);
var some = option.UnwrapSome();
// You can access `Value` directly here.
Console.WriteLine(some.Value); // Prints "3.14".
Option<double> option2 = new Option<double>.None();
// Throws `InvalidOperationException` because the underlying variant is `None`.
var bad = option.UnwrapSome();
```

> **Note**:
> Unwrapping is unsafe. Use only when runtime errors are ok.
## Stateful Matching

To reduce memory allocations, use the `Match` overload that accepts a generic state parameter as its first argument. This allows your match parameter lambdas to be `static` but still flow state through:
To reduce memory allocations, use the `Match` overload that accepts a generic state parameter as its first argument.

This allows your match parameter lambdas to be `static` but still flow state through:

```cs
using Dunet;
Expand Down
6 changes: 3 additions & 3 deletions src/Dunet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
<PackageReadmeFile>Readme.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/domn1995/dunet</RepositoryUrl>
<PackageTags>source; generator; discriminated; union; functional; tagged;</PackageTags>
<AssemblyVersion>1.9.0</AssemblyVersion>
<FileVersion>1.9.0</FileVersion>
<AssemblyVersion>1.10.0</AssemblyVersion>
<FileVersion>1.10.0</FileVersion>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReleaseNotes>https://github.com/domn1995/dunet/releases</PackageReleaseNotes>
<RepositoryType>git</RepositoryType>
<PackageIcon>favicon.png</PackageIcon>
<SignAssembly>False</SignAssembly>
<Version>1.9.0</Version>
<Version>1.10.0</Version>
<NeutralLanguage>en</NeutralLanguage>
<DevelopmentDependency>true</DevelopmentDependency>
<NoWarn>$(NoWarn);NU5128</NoWarn>
Expand Down

0 comments on commit 70d0624

Please sign in to comment.