Skip to content

Commit

Permalink
docs: document lazy evaluation of errors
Browse files Browse the repository at this point in the history
Refers to altmann#141
  • Loading branch information
mtyski committed Aug 4, 2022
1 parent ba590c7 commit 27151a6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,20 @@ With the methods ```FailIf()``` and ```OkIf()``` you can also write in a more re
var result = Result.FailIf(string.IsNullOrEmpty(firstName), "First Name is empty");
```

If an error instance should be lazily initialized, overloads accepting ```Func<string>``` or ```Func<IError>``` can be used to that effect:

```csharp
var list = Enumerable.Range(1, 9).ToList();

var result = Result.FailIf(
list.Any(IsDivisibleByTen),
() => new Error()$"Item {list.First(IsDivisibleByTen)}" should not be on the list));

bool IsDivisibleByTen(int i) => i % 10 == 0;

// rest of the code
```

### Try

In some scenarios you want to execute an action. If this action throws an exception then the exception should be catched and transformed to a result object.
Expand Down

0 comments on commit 27151a6

Please sign in to comment.