Skip to content

Commit

Permalink
Edit Result README.md.
Browse files Browse the repository at this point in the history
Update Release note.
  • Loading branch information
KeRNeLith committed Aug 15, 2018
1 parent 3c408ec commit 3df9d04
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/Here/Here.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,14 @@ Supported platforms:
<Company>Alexandre Rabérin</Company>
<IsPackable>true</IsPackable>
<PackageId>Here</PackageId>
<PackageReleaseNotes>➟ Release 0.3.0
<PackageReleaseNotes>➟ Release 0.4.0
- General:
- Add missing JetBrains annotations.

- For Maybes:
- Add explicit and implicit converters to Result/Result&lt;T&gt;/CustomResult&lt;T, TError&gt;/Result&lt;T, TError&gt;.
- Update to latest JetBrains annotations package.

- For Results:
- Result can now always embed an Exception (for Warning and Failure).
- Add scopes to safely return a Result of any type.
- Add explicit and implicit converters to Maybe&lt;T&gt;.</PackageReleaseNotes>
- Add extensions OnSuccess.
- Add extensions OnFailure.
- Add extensions OnAny.</PackageReleaseNotes>
<PackageTags>Here Functional C# Maybe Monad Result</PackageTags>
<PackageLicenseUrl>https://opensource.org/licenses/MIT</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/KeRNeLith/Here</PackageProjectUrl>
Expand Down
28 changes: 28 additions & 0 deletions src/Here/Result/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,34 @@ var result = MyFunctionRaiseException(); // Result.Fail()
// So you can keep focus on your code rather than exception that it can trigger.
```

### OnSuccess / OnFailure / OnAny

Results have extensions that allow branching code fluently. These extensions handle case the result is success, failure or run regardless of the result state.
These calls can be chained to easily produce complex treatments but keeping them readable and scalable.

See following examples for a quick overview. Note that each result type offers similar extensions.

```csharp
// In this example we call a method on a database that returns a Maybe<string>
Database.GetUser("Jack")
.ToResult()
.OnAny(() => Console.WriteLine("Hello"))
.OnSuccess(name => Console.WriteLine(name))
.OnFailure(() => Console.WriteLine("Anonymous"))
.OnAny(() => Console.WriteLine(", how are you?"));

// Output "Hello Jack, how are you?" if the Database contains a user named Jack
// Output "Hello Anonymous, how are you?" if the Database does not contain a user named Jack
// Obviously you can chain call and have nested calls
Database.GetUser("Jack")
.ToResult()
.OnSuccess(name => Database.GetAppointmentsFor(name)
.OnSuccess(appointments => Console.WriteLine($"Appointments for {name}: {appointments.ToString()}))
.OnFailure(() => Console.WriteLine($"Not any appointment for {name}.")))
.OnFailure(() => Console.WriteLine("No user named Jack."))
```

### Bridge to Maybe

It is possible to convert a `Result`, `Result<T>`, `CustomResult<TError>` or `Result<T, TError>` to a `Maybe<T>`.
Expand Down

0 comments on commit 3df9d04

Please sign in to comment.