File tree Expand file tree Collapse file tree
src/main/java/org/kunicki/functional_java Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package org .kunicki .functional_java ;
22
3+ import io .vavr .control .Either ;
4+
35record Person (String name , int age ) {
46}
57
@@ -18,6 +20,21 @@ default boolean isAgeValid(int age) {
1820
1921class FailingFast implements PersonValidator {
2022
23+ private Either <String , String > validateName (String name ) {
24+ return isNameValid (name ) ? Either .right (name ) : Either .left ("Invalid name" );
25+ }
26+
27+ private Either <String , Integer > validateAge (int age ) {
28+ return isAgeValid (age ) ? Either .right (age ) : Either .left ("Invalid age" );
29+ }
30+
31+ public Either <String , Person > validate (String name , int age ) {
32+ return validateName (name ).flatMap (n ->
33+ validateAge (age ).map (a ->
34+ new Person (n , a )
35+ )
36+ );
37+ }
2138}
2239
2340class Accumulating implements PersonValidator {
You can’t perform that action at this time.
0 commit comments