Skip to content

Commit f0559de

Browse files
committed
Fn1#uncurry and into* variants now accept general products
1 parent e3e2048 commit f0559de

File tree

19 files changed

+105
-98
lines changed

19 files changed

+105
-98
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
2222
## [3.0.2] - 2018-05-21
2323
### Added
2424
- `IterableLens#mapping`, an `Iso` that maps values
25+
- `Product2-8` interfaces, representing general product types
2526

2627
### Changed
2728
- `TypeSafeKey.Simple` now has a default `#apply` implementation
29+
- `Tuple2-8` now implement `Product2-8`
30+
- `Into2-8` now accepts a product of the same cardinality, instead of requiring a tuple
2831

2932
### Fixed
3033
- 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/functions/Fn2.java

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

3-
import com.jnape.palatable.lambda.adt.hlist.Tuple2;
3+
import com.jnape.palatable.lambda.adt.product.Product2;
44
import com.jnape.palatable.lambda.functor.Applicative;
55

66
import java.util.function.BiFunction;
@@ -64,11 +64,11 @@ default Fn2<B, A, C> flip() {
6464
}
6565

6666
/**
67-
* Returns an {@link Fn1} that takes the arguments as a <code>{@link Tuple2}&lt;A, B&gt;</code>.
67+
* Returns an {@link Fn1} that takes the arguments as a <code>{@link Product2}&lt;A, B&gt;</code>.
6868
*
69-
* @return an {@link Fn1} taking a {@link Tuple2}
69+
* @return an {@link Fn1} taking a {@link Product2}
7070
*/
71-
default Fn1<Tuple2<A, B>, C> uncurry() {
71+
default Fn1<? super Product2<? extends A, ? extends B>, C> uncurry() {
7272
return (ab) -> apply(ab._1(), ab._2());
7373
}
7474

src/main/java/com/jnape/palatable/lambda/functions/Fn3.java

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

3-
import com.jnape.palatable.lambda.adt.hlist.Tuple2;
3+
import com.jnape.palatable.lambda.adt.product.Product2;
44
import com.jnape.palatable.lambda.functor.Applicative;
55

66
import java.util.function.BiFunction;
@@ -64,13 +64,13 @@ default Fn3<B, A, C, D> flip() {
6464
}
6565

6666
/**
67-
* Returns an {@link Fn2} that takes the first two arguments as a <code>{@link Tuple2}&lt;A, B&gt;</code> and the
67+
* Returns an {@link Fn2} that takes the first two arguments as a <code>{@link Product2}&lt;A, B&gt;</code> and the
6868
* third argument.
6969
*
70-
* @return an {@link Fn2} taking a {@link Tuple2} and the third argument
70+
* @return an {@link Fn2} taking a {@link Product2} and the third argument
7171
*/
7272
@Override
73-
default Fn2<Tuple2<A, B>, C, D> uncurry() {
73+
default Fn2<? super Product2<? extends A, ? extends B>, C, D> uncurry() {
7474
return (ab, c) -> apply(ab._1(), ab._2(), c);
7575
}
7676

src/main/java/com/jnape/palatable/lambda/functions/Fn4.java

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

3-
import com.jnape.palatable.lambda.adt.hlist.Tuple2;
3+
import com.jnape.palatable.lambda.adt.product.Product2;
44
import com.jnape.palatable.lambda.functor.Applicative;
55

66
import java.util.function.BiFunction;
@@ -79,13 +79,13 @@ default Fn4<B, A, C, D, E> flip() {
7979
}
8080

8181
/**
82-
* Returns an {@link Fn3} that takes the first two arguments as a <code>{@link Tuple2}&lt;A, B&gt;</code> and the
82+
* Returns an {@link Fn3} that takes the first two arguments as a <code>{@link Product2}&lt;A, B&gt;</code> and the
8383
* third and fourth arguments.
8484
*
85-
* @return an {@link Fn3} taking a {@link Tuple2} and the third and fourth arguments
85+
* @return an {@link Fn3} taking a {@link Product2} and the third and fourth arguments
8686
*/
8787
@Override
88-
default Fn3<Tuple2<A, B>, C, D, E> uncurry() {
88+
default Fn3<? super Product2<? extends A, ? extends B>, C, D, E> uncurry() {
8989
return (ab, c, d) -> apply(ab._1(), ab._2(), c, d);
9090
}
9191

src/main/java/com/jnape/palatable/lambda/functions/Fn5.java

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

3-
import com.jnape.palatable.lambda.adt.hlist.Tuple2;
3+
import com.jnape.palatable.lambda.adt.product.Product2;
44
import com.jnape.palatable.lambda.functor.Applicative;
55

66
import java.util.function.BiFunction;
@@ -95,13 +95,13 @@ default Fn5<B, A, C, D, E, F> flip() {
9595
}
9696

9797
/**
98-
* Returns an {@link Fn4} that takes the first two arguments as a <code>{@link Tuple2}&lt;A, B&gt;</code> and the
98+
* Returns an {@link Fn4} that takes the first two arguments as a <code>{@link Product2}&lt;A, B&gt;</code> and the
9999
* remaining arguments.
100100
*
101-
* @return an {@link Fn4} taking a {@link Tuple2} and the remaining arguments
101+
* @return an {@link Fn4} taking a {@link Product2} and the remaining arguments
102102
*/
103103
@Override
104-
default Fn4<Tuple2<A, B>, C, D, E, F> uncurry() {
104+
default Fn4<? super Product2<? extends A, ? extends B>, C, D, E, F> uncurry() {
105105
return (ab, c, d, e) -> apply(ab._1(), ab._2(), c, d, e);
106106
}
107107

src/main/java/com/jnape/palatable/lambda/functions/Fn6.java

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

3-
import com.jnape.palatable.lambda.adt.hlist.Tuple2;
3+
import com.jnape.palatable.lambda.adt.product.Product2;
44
import com.jnape.palatable.lambda.functor.Applicative;
55

66
import java.util.function.BiFunction;
@@ -112,13 +112,13 @@ default Fn6<B, A, C, D, E, F, G> flip() {
112112
}
113113

114114
/**
115-
* Returns an {@link Fn5} that takes the first two arguments as a <code>{@link Tuple2}&lt;A, B&gt;</code> and the
115+
* Returns an {@link Fn5} that takes the first two arguments as a <code>{@link Product2}&lt;A, B&gt;</code> and the
116116
* remaining arguments.
117117
*
118-
* @return an {@link Fn5} taking a {@link Tuple2} and the remaining arguments
118+
* @return an {@link Fn5} taking a {@link Product2} and the remaining arguments
119119
*/
120120
@Override
121-
default Fn5<Tuple2<A, B>, C, D, E, F, G> uncurry() {
121+
default Fn5<? super Product2<? extends A, ? extends B>, C, D, E, F, G> uncurry() {
122122
return (ab, c, d, e, f) -> apply(ab._1(), ab._2(), c, d, e, f);
123123
}
124124

src/main/java/com/jnape/palatable/lambda/functions/Fn7.java

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

3-
import com.jnape.palatable.lambda.adt.hlist.Tuple2;
3+
import com.jnape.palatable.lambda.adt.product.Product2;
44
import com.jnape.palatable.lambda.functor.Applicative;
55

66
import java.util.function.BiFunction;
@@ -130,13 +130,13 @@ default Fn7<B, A, C, D, E, F, G, H> flip() {
130130
}
131131

132132
/**
133-
* Returns an {@link Fn6} that takes the first two arguments as a <code>{@link Tuple2}&lt;A, B&gt;</code> and the
133+
* Returns an {@link Fn6} that takes the first two arguments as a <code>{@link Product2}&lt;A, B&gt;</code> and the
134134
* remaining arguments.
135135
*
136-
* @return an {@link Fn6} taking a {@link Tuple2} and the remaining arguments
136+
* @return an {@link Fn6} taking a {@link Product2} and the remaining arguments
137137
*/
138138
@Override
139-
default Fn6<Tuple2<A, B>, C, D, E, F, G, H> uncurry() {
139+
default Fn6<? super Product2<? extends A, ? extends B>, C, D, E, F, G, H> uncurry() {
140140
return (ab, c, d, e, f, g) -> apply(ab._1(), ab._2(), c, d, e, f, g);
141141
}
142142

src/main/java/com/jnape/palatable/lambda/functions/Fn8.java

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

3-
import com.jnape.palatable.lambda.adt.hlist.Tuple2;
3+
import com.jnape.palatable.lambda.adt.product.Product2;
44
import com.jnape.palatable.lambda.functor.Applicative;
55

66
import java.util.function.BiFunction;
@@ -147,13 +147,13 @@ default Fn8<B, A, C, D, E, F, G, H, I> flip() {
147147
}
148148

149149
/**
150-
* Returns an {@link Fn7} that takes the first two arguments as a <code>{@link Tuple2}&lt;A, B&gt;</code> and the
150+
* Returns an {@link Fn7} that takes the first two arguments as a <code>{@link Product2}&lt;A, B&gt;</code> and the
151151
* remaining arguments.
152152
*
153-
* @return an {@link Fn7} taking a {@link Tuple2} and the remaining arguments
153+
* @return an {@link Fn7} taking a {@link Product2} and the remaining arguments
154154
*/
155155
@Override
156-
default Fn7<Tuple2<A, B>, C, D, E, F, G, H, I> uncurry() {
156+
default Fn7<? super Product2<? extends A, ? extends B>, C, D, E, F, G, H, I> uncurry() {
157157
return (ab, c, d, e, f, g, h) -> apply(ab._1(), ab._2(), c, d, e, f, g, h);
158158
}
159159

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,43 @@
11
package com.jnape.palatable.lambda.functions.builtin.fn2;
22

3-
import com.jnape.palatable.lambda.adt.hlist.Tuple2;
3+
import com.jnape.palatable.lambda.adt.product.Product2;
44
import com.jnape.palatable.lambda.functions.Fn1;
55
import com.jnape.palatable.lambda.functions.Fn2;
66

77
import java.util.function.BiFunction;
88

99
/**
10-
* Given a <code>{@link BiFunction}&lt;A, B, C&gt;</code> and a <code>{@link Tuple2}&lt;A, B&gt;</code>, destructure the
11-
* tuple and apply the slots as arguments to the function, returning the result.
10+
* Given a <code>{@link BiFunction}&lt;A, B, C&gt;</code> and a <code>{@link Product2}&lt;A, B&gt;</code>, destructure
11+
* the product and apply the slots as arguments to the function, returning the result.
1212
*
1313
* @param <A> the first argument type
1414
* @param <B> the second argument type
1515
* @param <C> the result type
1616
*/
17-
public final class Into<A, B, C> implements Fn2<BiFunction<? super A, ? super B, ? extends C>, Tuple2<A, B>, C> {
17+
public final class Into<A, B, C> implements Fn2<BiFunction<? super A, ? super B, ? extends C>, Product2<A, B>, C> {
1818

1919
private static final Into INSTANCE = new Into();
2020

2121
private Into() {
2222
}
2323

2424
@Override
25-
public C apply(BiFunction<? super A, ? super B, ? extends C> fn, Tuple2<A, B> tuple) {
26-
return tuple.into(fn);
25+
public C apply(BiFunction<? super A, ? super B, ? extends C> fn, Product2<A, B> product) {
26+
return product.into(fn);
2727
}
2828

2929
@SuppressWarnings("unchecked")
3030
public static <A, B, C> Into<A, B, C> into() {
3131
return INSTANCE;
3232
}
3333

34-
public static <A, B, C> Fn1<Tuple2<A, B>, C> into(BiFunction<? super A, ? super B, ? extends C> fn) {
34+
public static <A, B, C> Fn1<Product2<A, B>, C> into(
35+
BiFunction<? super A, ? super B, ? extends C> fn) {
3536
return Into.<A, B, C>into().apply(fn);
3637
}
3738

38-
public static <A, B, C> C into(BiFunction<? super A, ? super B, ? extends C> fn, Tuple2<A, B> tuple) {
39-
return Into.<A, B, C>into(fn).apply(tuple);
39+
public static <A, B, C> C into(BiFunction<? super A, ? super B, ? extends C> fn,
40+
Product2<A, B> product) {
41+
return Into.<A, B, C>into(fn).apply(product);
4042
}
4143
}
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
11
package com.jnape.palatable.lambda.functions.builtin.fn2;
22

3-
import com.jnape.palatable.lambda.adt.hlist.Tuple3;
3+
import com.jnape.palatable.lambda.adt.product.Product3;
44
import com.jnape.palatable.lambda.functions.Fn1;
55
import com.jnape.palatable.lambda.functions.Fn2;
66
import com.jnape.palatable.lambda.functions.Fn3;
77

88
/**
9-
* Given an <code>{@link Fn3}&lt;A, B, C, D&gt;</code> and a <code>{@link Tuple3}&lt;A, B, C&gt;</code>, destructure the
10-
* tuple and apply the slots as arguments to the function, returning the result.
9+
* Given an <code>{@link Fn3}&lt;A, B, C, D&gt;</code> and a <code>{@link Product3}&lt;A, B, C&gt;</code>, destructure
10+
* the product and apply the slots as arguments to the function, returning the result.
1111
*
1212
* @param <A> the first argument type
1313
* @param <B> the second argument type
1414
* @param <C> the third argument type
1515
* @param <D> the result type
1616
*/
17-
public final class Into3<A, B, C, D> implements Fn2<Fn3<? super A, ? super B, ? super C, ? extends D>, Tuple3<A, B, C>, D> {
17+
public final class Into3<A, B, C, D> implements Fn2<Fn3<? super A, ? super B, ? super C, ? extends D>, Product3<A, B, C>, D> {
1818

1919
private static final Into3 INSTANCE = new Into3();
2020

2121
@Override
22-
public D apply(Fn3<? super A, ? super B, ? super C, ? extends D> fn, Tuple3<A, B, C> tuple) {
23-
return tuple.into(fn);
22+
public D apply(Fn3<? super A, ? super B, ? super C, ? extends D> fn, Product3<A, B, C> product) {
23+
return product.into(fn);
2424
}
2525

2626
@SuppressWarnings("unchecked")
2727
public static <A, B, C, D> Into3<A, B, C, D> into3() {
2828
return INSTANCE;
2929
}
3030

31-
public static <A, B, C, D> Fn1<Tuple3<A, B, C>, D> into3(Fn3<? super A, ? super B, ? super C, ? extends D> fn) {
31+
public static <A, B, C, D> Fn1<Product3<A, B, C>, D> into3(Fn3<? super A, ? super B, ? super C, ? extends D> fn) {
3232
return Into3.<A, B, C, D>into3().apply(fn);
3333
}
3434

35-
public static <A, B, C, D> D into3(Fn3<? super A, ? super B, ? super C, ? extends D> fn, Tuple3<A, B, C> tuple) {
36-
return Into3.<A, B, C, D>into3(fn).apply(tuple);
35+
public static <A, B, C, D> D into3(Fn3<? super A, ? super B, ? super C, ? extends D> fn,
36+
Product3<A, B, C> product) {
37+
return Into3.<A, B, C, D>into3(fn).apply(product);
3738
}
3839
}
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
package com.jnape.palatable.lambda.functions.builtin.fn2;
22

3-
import com.jnape.palatable.lambda.adt.hlist.Tuple4;
3+
import com.jnape.palatable.lambda.adt.product.Product4;
44
import com.jnape.palatable.lambda.functions.Fn1;
55
import com.jnape.palatable.lambda.functions.Fn2;
66
import com.jnape.palatable.lambda.functions.Fn4;
77

88
/**
9-
* Given an <code>{@link Fn4}&lt;A, B, C, D, E&gt;</code> and a <code>{@link Tuple4}&lt;A, B, C, D&gt;</code>,
10-
* destructure the tuple and apply the slots as arguments to the function, returning the result.
9+
* Given an <code>{@link Fn4}&lt;A, B, C, D, E&gt;</code> and a <code>{@link Product4}&lt;A, B, C, D&gt;</code>,
10+
* destructure the product and apply the slots as arguments to the function, returning the result.
1111
*
1212
* @param <A> the first argument type
1313
* @param <B> the second argument type
1414
* @param <C> the third argument type
1515
* @param <D> the fourth argument type
1616
* @param <E> the result type
1717
*/
18-
public final class Into4<A, B, C, D, E> implements Fn2<Fn4<? super A, ? super B, ? super C, ? super D, ? extends E>, Tuple4<A, B, C, D>, E> {
18+
public final class Into4<A, B, C, D, E> implements Fn2<Fn4<? super A, ? super B, ? super C, ? super D, ? extends E>, Product4<A, B, C, D>, E> {
1919

2020
private static final Into4 INSTANCE = new Into4();
2121

2222
@Override
23-
public E apply(Fn4<? super A, ? super B, ? super C, ? super D, ? extends E> fn, Tuple4<A, B, C, D> tuple) {
24-
return tuple.<E>into(fn);
23+
public E apply(Fn4<? super A, ? super B, ? super C, ? super D, ? extends E> fn, Product4<A, B, C, D> product) {
24+
return product.<E>into(fn);
2525
}
2626

2727
@SuppressWarnings("unchecked")
2828
public static <A, B, C, D, E> Into4<A, B, C, D, E> into4() {
2929
return INSTANCE;
3030
}
3131

32-
public static <A, B, C, D, E> Fn1<Tuple4<A, B, C, D>, E> into4(
32+
public static <A, B, C, D, E> Fn1<Product4<A, B, C, D>, E> into4(
3333
Fn4<? super A, ? super B, ? super C, ? super D, ? extends E> fn) {
3434
return Into4.<A, B, C, D, E>into4().apply(fn);
3535
}
3636

3737
public static <A, B, C, D, E> E into4(Fn4<? super A, ? super B, ? super C, ? super D, ? extends E> fn,
38-
Tuple4<A, B, C, D> tuple) {
39-
return Into4.<A, B, C, D, E>into4(fn).apply(tuple);
38+
Product4<A, B, C, D> product) {
39+
return Into4.<A, B, C, D, E>into4(fn).apply(product);
4040
}
4141
}
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package com.jnape.palatable.lambda.functions.builtin.fn2;
22

3-
import com.jnape.palatable.lambda.adt.hlist.Tuple5;
3+
import com.jnape.palatable.lambda.adt.product.Product5;
44
import com.jnape.palatable.lambda.functions.Fn1;
55
import com.jnape.palatable.lambda.functions.Fn2;
66
import com.jnape.palatable.lambda.functions.Fn5;
77

88
/**
9-
* Given an <code>{@link Fn5}&lt;A, B, C, D, E, F&gt;</code> and a <code>{@link Tuple5}&lt;A, B, C, D, E&gt;</code>,
10-
* destructure the tuple and apply the slots as arguments to the function, returning the result.
9+
* Given an <code>{@link Fn5}&lt;A, B, C, D, E, F&gt;</code> and a <code>{@link Product5}&lt;A, B, C, D, E&gt;</code>,
10+
* destructure the product and apply the slots as arguments to the function, returning the result.
1111
*
1212
* @param <A> the first argument type
1313
* @param <B> the second argument type
@@ -16,28 +16,28 @@
1616
* @param <E> the fifth argument type
1717
* @param <F> the result type
1818
*/
19-
public final class Into5<A, B, C, D, E, F> implements Fn2<Fn5<? super A, ? super B, ? super C, ? super D, ? super E, ? extends F>, Tuple5<A, B, C, D, E>, F> {
19+
public final class Into5<A, B, C, D, E, F> implements Fn2<Fn5<? super A, ? super B, ? super C, ? super D, ? super E, ? extends F>, Product5<A, B, C, D, E>, F> {
2020

2121
private static final Into5 INSTANCE = new Into5();
2222

2323
@Override
2424
public F apply(Fn5<? super A, ? super B, ? super C, ? super D, ? super E, ? extends F> fn,
25-
Tuple5<A, B, C, D, E> tuple) {
26-
return tuple.<F>into(fn);
25+
Product5<A, B, C, D, E> product) {
26+
return product.<F>into(fn);
2727
}
2828

2929
@SuppressWarnings("unchecked")
3030
public static <A, B, C, D, E, F> Into5<A, B, C, D, E, F> into5() {
3131
return INSTANCE;
3232
}
3333

34-
public static <A, B, C, D, E, F> Fn1<Tuple5<A, B, C, D, E>, F> into5(
34+
public static <A, B, C, D, E, F> Fn1<Product5<A, B, C, D, E>, F> into5(
3535
Fn5<? super A, ? super B, ? super C, ? super D, ? super E, ? extends F> fn) {
3636
return Into5.<A, B, C, D, E, F>into5().apply(fn);
3737
}
3838

3939
public static <A, B, C, D, E, F> F into5(Fn5<? super A, ? super B, ? super C, ? super D, ? super E, ? extends F> fn,
40-
Tuple5<A, B, C, D, E> tuple) {
41-
return Into5.<A, B, C, D, E, F>into5(fn).apply(tuple);
40+
Product5<A, B, C, D, E> product) {
41+
return Into5.<A, B, C, D, E, F>into5(fn).apply(product);
4242
}
4343
}

0 commit comments

Comments
 (0)