Skip to content

Commit

Permalink
Update readme with example for partition
Browse files Browse the repository at this point in the history
  • Loading branch information
Mafii committed Oct 1, 2024
1 parent 0f0fd7e commit 9fcf7ca
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,40 @@ partial record Shape
</details>


### `GeneratePartitionExtension`
Set `GeneratePartitionExtension` to true to auto-generate partition methods for `IEnumerable<T>` of your type.

```cs
using Funcky;
using System.Text.Serialization;

[DiscriminatedUnion(GeneratePartitionExtension = true)]
public abstract partial record Result
{
public sealed partial record Ok() : Result;

public sealed partial record Warning(string Message) : Result;

public sealed partial record Error(string Message) : Result;
}
```

<details>

<summary>Usage</summary>

```cs
var results = new Result[] { new Result.Ok(), /* ... */ }

// N-Tuple extension method:
var (oks, warnings, errors) = results.Partition();

// Extension method with result selector:
var warningAndErrorCount = results.Partition(resultSelector: (_, warnings, errors) => warnings.Count + errors.Count);
```

</details>



[json-polymorphism-docs]: https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/polymorphism

0 comments on commit 9fcf7ca

Please sign in to comment.