1 package io.atlassian.fugue.extensions.step;
2
3 import io.atlassian.fugue.Either;
4 import io.atlassian.fugue.extensions.functions.Function6;
5 import io.atlassian.fugue.extensions.functions.Predicate6;
6
7 import java.util.function.Supplier;
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 public final class EitherStep6<A, B, C, D, E, F, LEFT> {
27 private final Either<LEFT, A> either1;
28 private final Either<LEFT, B> either2;
29 private final Either<LEFT, C> either3;
30 private final Either<LEFT, D> either4;
31 private final Either<LEFT, E> either5;
32 private final Either<LEFT, F> either6;
33
34 EitherStep6(Either<LEFT, A> either1, Either<LEFT, B> either2, Either<LEFT, C> either3, Either<LEFT, D> either4, Either<LEFT, E> either5,
35 Either<LEFT, F> either6) {
36 this.either1 = either1;
37 this.either2 = either2;
38 this.either3 = either3;
39 this.either4 = either4;
40 this.either5 = either5;
41 this.either6 = either6;
42 }
43
44
45
46
47
48
49
50
51
52
53
54
55
56 public EitherStep6<A, B, C, D, E, F, LEFT> filter(Predicate6<? super A, ? super B, ? super C, ? super D, ? super E, ? super F> predicate,
57 Supplier<? extends LEFT> unsatisfiedSupplier) {
58 Either<LEFT, F> filterEither6 = either1.flatMap(value1 -> either2.flatMap(value2 -> either3.flatMap(value3 -> either4.flatMap(value4 -> either5
59 .flatMap(value5 -> either6.filterOrElse(value6 -> predicate.test(value1, value2, value3, value4, value5, value6), unsatisfiedSupplier))))));
60 return new EitherStep6<>(either1, either2, either3, either4, either5, filterEither6);
61 }
62
63
64
65
66
67
68
69
70
71
72 public <Z> Either<LEFT, Z> yield(Function6<? super A, ? super B, ? super C, ? super D, ? super E, ? super F, Z> functor) {
73 return either1.flatMap(value1 -> either2.flatMap(value2 -> either3.flatMap(value3 -> either4.flatMap(value4 -> either5.flatMap(value5 -> either6
74 .map(value6 -> functor.apply(value1, value2, value3, value4, value5, value6)))))));
75 }
76
77 }