From c64315104a17131d5a6be68e524bed0c2051f936 Mon Sep 17 00:00:00 2001 From: Barion Date: Thu, 14 Nov 2024 18:22:22 +0100 Subject: [PATCH] Update README.md --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index c4c184f..b36ba09 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ # Ametrin.Optional A simple C#/.NET library containing various allocation free option types written by Barion at Ametrin Studios. -This is a rewrite of the Optional namespace in [Ametrin.Utils](https://github.com/BarionLP/Ametrin.Utils). -Warning: This is my 3rd take on options and I assume it will not be my last (Especially once .NET gets type unions). I try to avoid breaking changes. If I have to break something I'll create a legacy branch. +This is a rewrite of the Optional namespace in [Ametrin.Utils](https://github.com/BarionLP/Ametrin.Utils).
+**Warning**: This is my 3rd take on options and I assume it will not be my last (Especially once .NET gets type unions). I try to avoid breaking changes. If I have to break something I'll create a legacy branch. # Types ## Option\ -T or None +T or Error ```csharp -Option a = someT; // equivalent to Option.Of(someT) +Option a = someT; // equivalent to Option.Of(someT) - will produce Error if someT is null Option b = default; // equivalent to Option.Error() //careful that default is actually referencing Option and not T. Especially in conditional assignments. Option a = Option.Success(someT); //requires a nonnull value @@ -22,8 +22,8 @@ Option error = false; //equivalent to Option.Error() ## Result\ T or E ```csharp -Result success = someT; // equivalent to Option.Success() -Result error = someE; // equivalent to Option.Error() +Result success = someT; // equivalent to Result.Success(someT) +Result error = someE; // equivalent to Option.Error(someE) ``` ### Result\ T or Exception @@ -34,12 +34,12 @@ Success or Exception ## General API All option types in this library have a monadic, linq-like api to interact with them. -### Examples: +### Examples ```csharp -option.Select(value => value.ToString()).WhereNot(string.IsNullOfWhiteSpace).Or("John Doe"); +option.Select(value => value.ToString()).WhereNot(string.IsNullOrWhiteSpace).Or("John Doe"); option.Where(a => a > 5).Select(a => a * 5).Consume(a => process(a), () => reportFailure()) (optionA, optionB).Select((a, b) => a * b); (optionA, optionB).Consume((a, b) => ...); ``` -There is a `...OrNone` alternative most `Try...` methods. If not, I'm happy to accept pull request. -Not all functions might exist for every option type. Feel free to PR them. \ No newline at end of file +There is an alternative most `Try...` methods that return an option. If not, I'm happy to accept pull request.
+If you are missing something feel free to create an issue or PR (talk to me before so i agree on the design)