Skip to content

Commit

Permalink
Update release notes and README.md.
Browse files Browse the repository at this point in the history
  • Loading branch information
KeRNeLith committed Sep 2, 2018
1 parent e6a73c1 commit 734d476
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/Here/Here.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,20 @@ Supported platforms:
<Company>Alexandre Rabérin</Company>
<IsPackable>true</IsPackable>
<PackageId>Here</PackageId>
<PackageReleaseNotes>➟ Release 0.4.0
<PackageReleaseNotes>➟ Release 0.5.0
- General:
- Update to latest JetBrains annotations package.
- Extend library compatibility until .NET Framework 2.0.

- For Maybes:
- Add implicit conversion to boolean to handle test like a simple boolean.
- Remove true/false operators (replaced by the implicit conversion to boolean).
- Add extension on string: NoneIfNullOrSpace.
- Add extensions on Maybe&lt;string&gt;: NoneIfEmpty and NoneIfNullOrSpace.

- For Results:
- Add extensions OnSuccess.
- Add extensions OnFailure.
- Add extensions OnAny.</PackageReleaseNotes>
- Add implicit conversion to boolean to handle test like a simple boolean.
- Add "Ensure" extensions that allow to check a predicate on each Result type.
- Add cast methods on each Result type to create a Result of another type or with a different value type.</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
45 changes: 45 additions & 0 deletions src/Here/Result/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ The necessity to have a message for warnings and errors is motivated by the need

Then you have `IResult<T>` and `IResultError<TError>` that respectively provide a `Value` and a custom `Error`.

Note that each one support simple conditional test like boolean when you do not want look at extra data, see following example:

```csharp
Result<int> result = Result.Ok(42);
if (result.IsSuccess)
Console.WriteLine(result.Value);

// Equivalent to
if (result)
Console.WriteLine(result.Value);
```

### Safe Scopes

If you want to run code that should return a Result safely, you can use Result scopes to do this.
Expand Down Expand Up @@ -177,6 +189,39 @@ Database.GetUser("Jack")
.OnFailure(() => Console.WriteLine("No user named Jack."))
```

### Ensure

With `Result` (and all results structures) you can run treatments, get the result of it, and then ensure that it meets other requirements.

Look at the following example (obviously the example is very dummy):

```csharp
public void Result CheckCountOver(int N)
{
Result<int> myCount = TreatmentThatCountSomething();

// Let assume we only consider the final result success if the count is over N
// So the result will be converted to a failure if the predicate is not matched.
return myCount.Ensure(count => count > N, $"Count must be over {N}.");
}

```

### Cast

Results support "downcast" implicitly. For example a `Result<int, ErrorType>` can be implicitly converted to a `Result<int>`. But the opposite is not possible.
To do this you can use `Cast` methods that each result type provide. For example if you want to create a `Result<double>` from a simple `Result` you can do like following:

```csharp
Result res = Result.Ok();

Result<double> resDouble = res.Cast<double>(12.5f);
// Or
Result<double> resDouble = res.Cast<double>(() => GetADouble() * 2.5);
```

Result with more data inside provide less Cast methods because as said before the implicit conversion is used when you specify the target type.

### 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 734d476

Please sign in to comment.