11package com .jnape .palatable .lambda .adt .coproduct ;
22
3+ import com .jnape .palatable .lambda .adt .Maybe ;
34import com .jnape .palatable .lambda .adt .hlist .Tuple5 ;
45import com .jnape .palatable .lambda .functions .Fn1 ;
56
6- import java .util .Optional ;
77import java .util .function .Function ;
88
9+ import static com .jnape .palatable .lambda .adt .Maybe .just ;
10+ import static com .jnape .palatable .lambda .adt .Maybe .nothing ;
911import static com .jnape .palatable .lambda .adt .hlist .HList .tuple ;
1012import static com .jnape .palatable .lambda .functions .Fn1 .fn1 ;
1113import static com .jnape .palatable .lambda .functions .builtin .fn1 .Constantly .constantly ;
@@ -84,20 +86,20 @@ public <R> R match(Function<? super A, ? extends R> aFn, Function<? super B, ? e
8486 * @return a tuple of the coproduct projection
8587 * @see CoProduct2#project()
8688 */
87- default Tuple5 <Optional <A >, Optional <B >, Optional <C >, Optional <D >, Optional <E >> project () {
88- return match (a -> tuple (Optional . of (a ), Optional . empty (), Optional . empty (), Optional . empty (), Optional . empty ()),
89- b -> tuple (Optional . empty (), Optional . of (b ), Optional . empty (), Optional . empty (), Optional . empty ()),
90- c -> tuple (Optional . empty (), Optional . empty (), Optional . of (c ), Optional . empty (), Optional . empty ()),
91- d -> tuple (Optional . empty (), Optional . empty (), Optional . empty (), Optional . of (d ), Optional . empty ()),
92- e -> tuple (Optional . empty (), Optional . empty (), Optional . empty (), Optional . empty (), Optional . of (e )));
89+ default Tuple5 <Maybe <A >, Maybe <B >, Maybe <C >, Maybe <D >, Maybe <E >> project () {
90+ return match (a -> tuple (just (a ), nothing (), nothing (), nothing (), nothing ()),
91+ b -> tuple (nothing (), just (b ), nothing (), nothing (), nothing ()),
92+ c -> tuple (nothing (), nothing (), just (c ), nothing (), nothing ()),
93+ d -> tuple (nothing (), nothing (), nothing (), just (d ), nothing ()),
94+ e -> tuple (nothing (), nothing (), nothing (), nothing (), just (e )));
9395 }
9496
9597 /**
9698 * Convenience method for projecting this coproduct onto a tuple and then extracting the first slot value.
9799 *
98100 * @return an optional value representing the projection of the "a" type index
99101 */
100- default Optional <A > projectA () {
102+ default Maybe <A > projectA () {
101103 return project ()._1 ();
102104 }
103105
@@ -106,7 +108,7 @@ default Optional<A> projectA() {
106108 *
107109 * @return an optional value representing the projection of the "b" type index
108110 */
109- default Optional <B > projectB () {
111+ default Maybe <B > projectB () {
110112 return project ()._2 ();
111113 }
112114
@@ -115,7 +117,7 @@ default Optional<B> projectB() {
115117 *
116118 * @return an optional value representing the projection of the "c" type index
117119 */
118- default Optional <C > projectC () {
120+ default Maybe <C > projectC () {
119121 return project ()._3 ();
120122 }
121123
@@ -124,7 +126,7 @@ default Optional<C> projectC() {
124126 *
125127 * @return an optional value representing the projection of the "d" type index
126128 */
127- default Optional <D > projectD () {
129+ default Maybe <D > projectD () {
128130 return project ()._4 ();
129131 }
130132
@@ -133,7 +135,7 @@ default Optional<D> projectD() {
133135 *
134136 * @return an optional value representing the projection of the "e" type index
135137 */
136- default Optional <E > projectE () {
138+ default Maybe <E > projectE () {
137139 return project ()._5 ();
138140 }
139141
0 commit comments