Skip to content

Commit fb18ccf

Browse files
committed
coproducts now all project into general products
1 parent f0559de commit fb18ccf

File tree

8 files changed

+65
-64
lines changed

8 files changed

+65
-64
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
2828
- `TypeSafeKey.Simple` now has a default `#apply` implementation
2929
- `Tuple2-8` now implement `Product2-8`
3030
- `Into2-8` now accepts a product of the same cardinality, instead of requiring a tuple
31+
- `CoProduct2-8#project` now return generalized products
3132

3233
### Fixed
3334
- mapped `TypeSafeKey` instances can be used for initial put in an `HMap`, and the base key can be used to retrieve them

src/main/java/com/jnape/palatable/lambda/adt/coproduct/CoProduct2.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.jnape.palatable.lambda.adt.Either;
44
import com.jnape.palatable.lambda.adt.Maybe;
55
import com.jnape.palatable.lambda.adt.choice.Choice2;
6-
import com.jnape.palatable.lambda.adt.hlist.Tuple2;
6+
import com.jnape.palatable.lambda.adt.product.Product2;
77
import com.jnape.palatable.lambda.functions.Fn1;
88

99
import java.util.function.Function;
@@ -70,18 +70,18 @@ public <R> R match(Function<? super A, ? extends R> aFn, Function<? super B, ? e
7070
}
7171

7272
/**
73-
* Project this coproduct onto a tuple, such that the slot in the tuple that corresponds to this coproduct's value
74-
* is present, while the other slots are absent.
73+
* Project this coproduct onto a product, such that the index in the product that corresponds to this coproduct's
74+
* value is present, while the other indices are absent.
7575
*
76-
* @return a tuple of the coproduct projection
76+
* @return a product of the coproduct projection
7777
*/
78-
default Tuple2<Maybe<A>, Maybe<B>> project() {
78+
default Product2<Maybe<A>, Maybe<B>> project() {
7979
return match(a -> tuple(just(a), nothing()),
8080
b -> tuple(nothing(), just(b)));
8181
}
8282

8383
/**
84-
* Convenience method for projecting this coproduct onto a tuple and then extracting the first slot value.
84+
* Convenience method for projecting this coproduct onto a product and then extracting the first slot value.
8585
*
8686
* @return an optional value representing the projection of the "a" type index
8787
*/
@@ -90,7 +90,7 @@ default Maybe<A> projectA() {
9090
}
9191

9292
/**
93-
* Convenience method for projecting this coproduct onto a tuple and then extracting the second slot value.
93+
* Convenience method for projecting this coproduct onto a product and then extracting the second slot value.
9494
*
9595
* @return an optional value representing the projection of the "b" type index
9696
*/

src/main/java/com/jnape/palatable/lambda/adt/coproduct/CoProduct3.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.jnape.palatable.lambda.adt.coproduct;
22

33
import com.jnape.palatable.lambda.adt.Maybe;
4-
import com.jnape.palatable.lambda.adt.hlist.Tuple3;
4+
import com.jnape.palatable.lambda.adt.product.Product3;
55
import com.jnape.palatable.lambda.functions.Fn1;
66

77
import java.util.function.Function;
@@ -82,19 +82,19 @@ public <R> R match(Function<? super A, ? extends R> aFn, Function<? super B, ? e
8282
}
8383

8484
/**
85-
* Project this coproduct onto a tuple.
85+
* Project this coproduct onto a product.
8686
*
87-
* @return a tuple of the coproduct projection
87+
* @return a product of the coproduct projection
8888
* @see CoProduct2#project()
8989
*/
90-
default Tuple3<Maybe<A>, Maybe<B>, Maybe<C>> project() {
90+
default Product3<Maybe<A>, Maybe<B>, Maybe<C>> project() {
9191
return match(a -> tuple(just(a), nothing(), nothing()),
9292
b -> tuple(nothing(), just(b), nothing()),
9393
c -> tuple(nothing(), nothing(), just(c)));
9494
}
9595

9696
/**
97-
* Convenience method for projecting this coproduct onto a tuple and then extracting the first slot value.
97+
* Convenience method for projecting this coproduct onto a product and then extracting the first slot value.
9898
*
9999
* @return an optional value representing the projection of the "a" type index
100100
*/
@@ -103,7 +103,7 @@ default Maybe<A> projectA() {
103103
}
104104

105105
/**
106-
* Convenience method for projecting this coproduct onto a tuple and then extracting the second slot value.
106+
* Convenience method for projecting this coproduct onto a product and then extracting the second slot value.
107107
*
108108
* @return an optional value representing the projection of the "b" type index
109109
*/
@@ -112,7 +112,7 @@ default Maybe<B> projectB() {
112112
}
113113

114114
/**
115-
* Convenience method for projecting this coproduct onto a tuple and then extracting the third slot value.
115+
* Convenience method for projecting this coproduct onto a product and then extracting the third slot value.
116116
*
117117
* @return an optional value representing the projection of the "c" type index
118118
*/

src/main/java/com/jnape/palatable/lambda/adt/coproduct/CoProduct4.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.jnape.palatable.lambda.adt.coproduct;
22

33
import com.jnape.palatable.lambda.adt.Maybe;
4-
import com.jnape.palatable.lambda.adt.hlist.Tuple4;
4+
import com.jnape.palatable.lambda.adt.product.Product4;
55
import com.jnape.palatable.lambda.functions.Fn1;
66

77
import java.util.function.Function;
@@ -90,20 +90,20 @@ public <R> R match(Function<? super A, ? extends R> aFn, Function<? super B, ? e
9090
}
9191

9292
/**
93-
* Project this coproduct onto a tuple.
93+
* Project this coproduct onto a product.
9494
*
95-
* @return a tuple of the coproduct projection
95+
* @return a product of the coproduct projection
9696
* @see CoProduct2#project()
9797
*/
98-
default Tuple4<Maybe<A>, Maybe<B>, Maybe<C>, Maybe<D>> project() {
98+
default Product4<Maybe<A>, Maybe<B>, Maybe<C>, Maybe<D>> project() {
9999
return match(a -> tuple(just(a), nothing(), nothing(), nothing()),
100100
b -> tuple(nothing(), just(b), nothing(), nothing()),
101101
c -> tuple(nothing(), nothing(), just(c), nothing()),
102102
d -> tuple(nothing(), nothing(), nothing(), just(d)));
103103
}
104104

105105
/**
106-
* Convenience method for projecting this coproduct onto a tuple and then extracting the first slot value.
106+
* Convenience method for projecting this coproduct onto a product and then extracting the first slot value.
107107
*
108108
* @return an optional value representing the projection of the "a" type index
109109
*/
@@ -112,7 +112,7 @@ default Maybe<A> projectA() {
112112
}
113113

114114
/**
115-
* Convenience method for projecting this coproduct onto a tuple and then extracting the second slot value.
115+
* Convenience method for projecting this coproduct onto a product and then extracting the second slot value.
116116
*
117117
* @return an optional value representing the projection of the "b" type index
118118
*/
@@ -121,7 +121,7 @@ default Maybe<B> projectB() {
121121
}
122122

123123
/**
124-
* Convenience method for projecting this coproduct onto a tuple and then extracting the third slot value.
124+
* Convenience method for projecting this coproduct onto a product and then extracting the third slot value.
125125
*
126126
* @return an optional value representing the projection of the "c" type index
127127
*/
@@ -130,7 +130,7 @@ default Maybe<C> projectC() {
130130
}
131131

132132
/**
133-
* Convenience method for projecting this coproduct onto a tuple and then extracting the fourth slot value.
133+
* Convenience method for projecting this coproduct onto a product and then extracting the fourth slot value.
134134
*
135135
* @return an optional value representing the projection of the "d" type index
136136
*/

src/main/java/com/jnape/palatable/lambda/adt/coproduct/CoProduct5.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.jnape.palatable.lambda.adt.coproduct;
22

33
import com.jnape.palatable.lambda.adt.Maybe;
4-
import com.jnape.palatable.lambda.adt.hlist.Tuple5;
4+
import com.jnape.palatable.lambda.adt.product.Product5;
55
import com.jnape.palatable.lambda.functions.Fn1;
66

77
import java.util.function.Function;
@@ -98,12 +98,12 @@ public <R> R match(Function<? super A, ? extends R> aFn, Function<? super B, ? e
9898
}
9999

100100
/**
101-
* Project this coproduct onto a tuple.
101+
* Project this coproduct onto a product.
102102
*
103-
* @return a tuple of the coproduct projection
103+
* @return a product of the coproduct projection
104104
* @see CoProduct2#project()
105105
*/
106-
default Tuple5<Maybe<A>, Maybe<B>, Maybe<C>, Maybe<D>, Maybe<E>> project() {
106+
default Product5<Maybe<A>, Maybe<B>, Maybe<C>, Maybe<D>, Maybe<E>> project() {
107107
return match(a -> tuple(just(a), nothing(), nothing(), nothing(), nothing()),
108108
b -> tuple(nothing(), just(b), nothing(), nothing(), nothing()),
109109
c -> tuple(nothing(), nothing(), just(c), nothing(), nothing()),
@@ -112,7 +112,7 @@ default Tuple5<Maybe<A>, Maybe<B>, Maybe<C>, Maybe<D>, Maybe<E>> project() {
112112
}
113113

114114
/**
115-
* Convenience method for projecting this coproduct onto a tuple and then extracting the first slot value.
115+
* Convenience method for projecting this coproduct onto a product and then extracting the first slot value.
116116
*
117117
* @return an optional value representing the projection of the "a" type index
118118
*/
@@ -121,7 +121,7 @@ default Maybe<A> projectA() {
121121
}
122122

123123
/**
124-
* Convenience method for projecting this coproduct onto a tuple and then extracting the second slot value.
124+
* Convenience method for projecting this coproduct onto a product and then extracting the second slot value.
125125
*
126126
* @return an optional value representing the projection of the "b" type index
127127
*/
@@ -130,7 +130,7 @@ default Maybe<B> projectB() {
130130
}
131131

132132
/**
133-
* Convenience method for projecting this coproduct onto a tuple and then extracting the third slot value.
133+
* Convenience method for projecting this coproduct onto a product and then extracting the third slot value.
134134
*
135135
* @return an optional value representing the projection of the "c" type index
136136
*/
@@ -139,7 +139,7 @@ default Maybe<C> projectC() {
139139
}
140140

141141
/**
142-
* Convenience method for projecting this coproduct onto a tuple and then extracting the fourth slot value.
142+
* Convenience method for projecting this coproduct onto a product and then extracting the fourth slot value.
143143
*
144144
* @return an optional value representing the projection of the "d" type index
145145
*/
@@ -148,7 +148,7 @@ default Maybe<D> projectD() {
148148
}
149149

150150
/**
151-
* Convenience method for projecting this coproduct onto a tuple and then extracting the fifth slot value.
151+
* Convenience method for projecting this coproduct onto a product and then extracting the fifth slot value.
152152
*
153153
* @return an optional value representing the projection of the "e" type index
154154
*/

src/main/java/com/jnape/palatable/lambda/adt/coproduct/CoProduct6.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.jnape.palatable.lambda.adt.Maybe;
44
import com.jnape.palatable.lambda.adt.choice.Choice5;
5-
import com.jnape.palatable.lambda.adt.hlist.Tuple6;
5+
import com.jnape.palatable.lambda.adt.product.Product6;
66
import com.jnape.palatable.lambda.functions.Fn1;
77

88
import java.util.function.Function;
@@ -79,12 +79,12 @@ public <R> R match(Function<? super A, ? extends R> aFn, Function<? super B, ? e
7979
}
8080

8181
/**
82-
* Project this coproduct onto a tuple.
82+
* Project this coproduct onto a product.
8383
*
84-
* @return a tuple of the coproduct projection
84+
* @return a product of the coproduct projection
8585
* @see CoProduct2#project()
8686
*/
87-
default Tuple6<Maybe<A>, Maybe<B>, Maybe<C>, Maybe<D>, Maybe<E>, Maybe<F>> project() {
87+
default Product6<Maybe<A>, Maybe<B>, Maybe<C>, Maybe<D>, Maybe<E>, Maybe<F>> project() {
8888
return match(a -> tuple(just(a), nothing(), nothing(), nothing(), nothing(), nothing()),
8989
b -> tuple(nothing(), just(b), nothing(), nothing(), nothing(), nothing()),
9090
c -> tuple(nothing(), nothing(), just(c), nothing(), nothing(), nothing()),
@@ -94,7 +94,7 @@ default Tuple6<Maybe<A>, Maybe<B>, Maybe<C>, Maybe<D>, Maybe<E>, Maybe<F>> proje
9494
}
9595

9696
/**
97-
* Convenience method for projecting this coproduct onto a tuple and then extracting the first slot value.
97+
* Convenience method for projecting this coproduct onto a product and then extracting the first slot value.
9898
*
9999
* @return an optional value representing the projection of the "a" type index
100100
*/
@@ -103,7 +103,7 @@ default Maybe<A> projectA() {
103103
}
104104

105105
/**
106-
* Convenience method for projecting this coproduct onto a tuple and then extracting the second slot value.
106+
* Convenience method for projecting this coproduct onto a product and then extracting the second slot value.
107107
*
108108
* @return an optional value representing the projection of the "b" type index
109109
*/
@@ -112,7 +112,7 @@ default Maybe<B> projectB() {
112112
}
113113

114114
/**
115-
* Convenience method for projecting this coproduct onto a tuple and then extracting the third slot value.
115+
* Convenience method for projecting this coproduct onto a product and then extracting the third slot value.
116116
*
117117
* @return an optional value representing the projection of the "c" type index
118118
*/
@@ -121,7 +121,7 @@ default Maybe<C> projectC() {
121121
}
122122

123123
/**
124-
* Convenience method for projecting this coproduct onto a tuple and then extracting the fourth slot value.
124+
* Convenience method for projecting this coproduct onto a product and then extracting the fourth slot value.
125125
*
126126
* @return an optional value representing the projection of the "d" type index
127127
*/
@@ -130,7 +130,7 @@ default Maybe<D> projectD() {
130130
}
131131

132132
/**
133-
* Convenience method for projecting this coproduct onto a tuple and then extracting the fifth slot value.
133+
* Convenience method for projecting this coproduct onto a product and then extracting the fifth slot value.
134134
*
135135
* @return an optional value representing the projection of the "e" type index
136136
*/
@@ -139,7 +139,7 @@ default Maybe<E> projectE() {
139139
}
140140

141141
/**
142-
* Convenience method for projecting this coproduct onto a tuple and then extracting the sixth slot value.
142+
* Convenience method for projecting this coproduct onto a product and then extracting the sixth slot value.
143143
*
144144
* @return an optional value representing the projection of the "f" type index
145145
*/

src/main/java/com/jnape/palatable/lambda/adt/coproduct/CoProduct7.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.jnape.palatable.lambda.adt.Maybe;
44
import com.jnape.palatable.lambda.adt.choice.Choice6;
5-
import com.jnape.palatable.lambda.adt.hlist.Tuple7;
5+
import com.jnape.palatable.lambda.adt.product.Product7;
66
import com.jnape.palatable.lambda.functions.Fn1;
77

88
import java.util.function.Function;
@@ -82,12 +82,12 @@ public <R> R match(Function<? super A, ? extends R> aFn, Function<? super B, ? e
8282
}
8383

8484
/**
85-
* Project this coproduct onto a tuple.
85+
* Project this coproduct onto a product.
8686
*
87-
* @return a tuple of the coproduct projection
87+
* @return a product of the coproduct projection
8888
* @see CoProduct2#project()
8989
*/
90-
default Tuple7<Maybe<A>, Maybe<B>, Maybe<C>, Maybe<D>, Maybe<E>, Maybe<F>, Maybe<G>> project() {
90+
default Product7<Maybe<A>, Maybe<B>, Maybe<C>, Maybe<D>, Maybe<E>, Maybe<F>, Maybe<G>> project() {
9191
return match(a -> tuple(just(a), nothing(), nothing(), nothing(), nothing(), nothing(), nothing()),
9292
b -> tuple(nothing(), just(b), nothing(), nothing(), nothing(), nothing(), nothing()),
9393
c -> tuple(nothing(), nothing(), just(c), nothing(), nothing(), nothing(), nothing()),
@@ -98,7 +98,7 @@ default Tuple7<Maybe<A>, Maybe<B>, Maybe<C>, Maybe<D>, Maybe<E>, Maybe<F>, Maybe
9898
}
9999

100100
/**
101-
* Convenience method for projecting this coproduct onto a tuple and then extracting the first slot value.
101+
* Convenience method for projecting this coproduct onto a product and then extracting the first slot value.
102102
*
103103
* @return an optional value representing the projection of the "a" type index
104104
*/
@@ -107,7 +107,7 @@ default Maybe<A> projectA() {
107107
}
108108

109109
/**
110-
* Convenience method for projecting this coproduct onto a tuple and then extracting the second slot value.
110+
* Convenience method for projecting this coproduct onto a product and then extracting the second slot value.
111111
*
112112
* @return an optional value representing the projection of the "b" type index
113113
*/
@@ -116,7 +116,7 @@ default Maybe<B> projectB() {
116116
}
117117

118118
/**
119-
* Convenience method for projecting this coproduct onto a tuple and then extracting the third slot value.
119+
* Convenience method for projecting this coproduct onto a product and then extracting the third slot value.
120120
*
121121
* @return an optional value representing the projection of the "c" type index
122122
*/
@@ -125,7 +125,7 @@ default Maybe<C> projectC() {
125125
}
126126

127127
/**
128-
* Convenience method for projecting this coproduct onto a tuple and then extracting the fourth slot value.
128+
* Convenience method for projecting this coproduct onto a product and then extracting the fourth slot value.
129129
*
130130
* @return an optional value representing the projection of the "d" type index
131131
*/
@@ -134,7 +134,7 @@ default Maybe<D> projectD() {
134134
}
135135

136136
/**
137-
* Convenience method for projecting this coproduct onto a tuple and then extracting the fifth slot value.
137+
* Convenience method for projecting this coproduct onto a product and then extracting the fifth slot value.
138138
*
139139
* @return an optional value representing the projection of the "e" type index
140140
*/
@@ -143,7 +143,7 @@ default Maybe<E> projectE() {
143143
}
144144

145145
/**
146-
* Convenience method for projecting this coproduct onto a tuple and then extracting the sixth slot value.
146+
* Convenience method for projecting this coproduct onto a product and then extracting the sixth slot value.
147147
*
148148
* @return an optional value representing the projection of the "f" type index
149149
*/
@@ -152,7 +152,7 @@ default Maybe<F> projectF() {
152152
}
153153

154154
/**
155-
* Convenience method for projecting this coproduct onto a tuple and then extracting the seventh slot value.
155+
* Convenience method for projecting this coproduct onto a product and then extracting the seventh slot value.
156156
*
157157
* @return an optional value representing the projection of the "g" type index
158158
*/

0 commit comments

Comments
 (0)