diff --git a/readme.md b/readme.md index 4c73082..7fa8ef2 100644 --- a/readme.md +++ b/readme.md @@ -130,4 +130,38 @@ partial record Shape +### `GeneratePartitionExtension` +Set `GeneratePartitionExtension` to true to auto-generate partition methods for `IEnumerable` 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; +} +``` + +
+ +Usage + +```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); +``` + +
+ [json-polymorphism-docs]: https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/polymorphism