aboutsummaryrefslogtreecommitdiff
path: root/readme.md
diff options
context:
space:
mode:
Diffstat (limited to 'readme.md')
-rw-r--r--readme.md20
1 files changed, 7 insertions, 13 deletions
diff --git a/readme.md b/readme.md
index 8a1a720..cad76ee 100644
--- a/readme.md
+++ b/readme.md
@@ -28,28 +28,22 @@ the use of which being problematic in performance-sensitive contexts.
28import static org.pacien.lemonad.attempt.Attempt.*; 28import static org.pacien.lemonad.attempt.Attempt.*;
29 29
30(tree.hasLemon() ? success(tree.getLemon()) : failure("No lemon.")) 30(tree.hasLemon() ? success(tree.getLemon()) : failure("No lemon."))
31 .recoverError(__ -> store.buyLemon()) 31 .recoverError(error -> store.buyLemon())
32 .transformResult(this::makeLemonade) 32 .transformResult(this::makeLemonade)
33 .ifSuccess(this::drink); 33 .ifSuccess(this::drink);
34``` 34```
35 35
36### Validation 36### Validation
37 37
38The `Validation` monad represents a validation of a subject which can be either valid or invalid. 38The `Validation` monad represents a validation of a subject which can be successful or failed with errors.
39In the latter case, the monad wraps one or multiple validation errors in addition to the subject of the validation. 39Those errors are aggregated from all the checks that have failed.
40
41The `Validator` functional interface represents a function which performs verification operations on a supplied subject and returns
42a `Validation`.
43`Validator`s can be composed to perform verifications against multiple criteria and obtain an aggregated `Validation`.
44 40
45```java 41```java
46import static org.pacien.lemonad.validation.Validator.*; 42import org.pacien.lemonad.validation.Validation;
47
48var validator = validatingAll(
49 ensuringPredicate(not(Lemon::isRotten), "Bad lemon."),
50 validatingField(Lemon::juiceContent, ensuringPredicate(mL -> mL >= 40, "Not juicy.")));
51 43
52validator.validate(lemon) 44Validation.of(lemon)
45 .validate(not(Lemon::isRotten), "Bad lemon.")
46 .validate(Lemon::juiceContent, mL -> mL >= 40, "Not juicy")
53 .ifValid(this::makeLemonade) 47 .ifValid(this::makeLemonade)
54 .ifInvalid(errors -> makeLifeTakeTheLemonBack()); 48 .ifInvalid(errors -> makeLifeTakeTheLemonBack());
55``` 49```