Skip to content

Commit ed6a066

Browse files
committed
Updating javadoc, reorganizing code, dropping HNil#snoc
1 parent 736dcb0 commit ed6a066

18 files changed

+112
-129
lines changed

src/main/java/com/jnape/palatable/lambda/adt/hlist/HList.java

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ public static <Head> SingletonHList<Head> singletonHList(Head head) {
8989
* @return the 2-element HList
9090
* @see Tuple2
9191
*/
92-
@SuppressWarnings("JavaDoc")
9392
public static <_1, _2> Tuple2<_1, _2> tuple(_1 _1, _2 _2) {
9493
return singletonHList(_2).cons(_1);
9594
}
@@ -106,7 +105,6 @@ public static <_1, _2> Tuple2<_1, _2> tuple(_1 _1, _2 _2) {
106105
* @return the 3-element HList
107106
* @see Tuple3
108107
*/
109-
@SuppressWarnings("JavaDoc")
110108
public static <_1, _2, _3> Tuple3<_1, _2, _3> tuple(_1 _1, _2 _2, _3 _3) {
111109
return tuple(_2, _3).cons(_1);
112110
}
@@ -125,7 +123,6 @@ public static <_1, _2, _3> Tuple3<_1, _2, _3> tuple(_1 _1, _2 _2, _3 _3) {
125123
* @return the 4-element HList
126124
* @see Tuple4
127125
*/
128-
@SuppressWarnings("JavaDoc")
129126
public static <_1, _2, _3, _4> Tuple4<_1, _2, _3, _4> tuple(_1 _1, _2 _2, _3 _3, _4 _4) {
130127
return tuple(_2, _3, _4).cons(_1);
131128
}
@@ -146,7 +143,6 @@ public static <_1, _2, _3, _4> Tuple4<_1, _2, _3, _4> tuple(_1 _1, _2 _2, _3 _3,
146143
* @return the 5-element HList
147144
* @see Tuple5
148145
*/
149-
@SuppressWarnings("JavaDoc")
150146
public static <_1, _2, _3, _4, _5> Tuple5<_1, _2, _3, _4, _5> tuple(_1 _1, _2 _2, _3 _3, _4 _4, _5 _5) {
151147
return tuple(_2, _3, _4, _5).cons(_1);
152148
}
@@ -169,7 +165,6 @@ public static <_1, _2, _3, _4, _5> Tuple5<_1, _2, _3, _4, _5> tuple(_1 _1, _2 _2
169165
* @return the 6-element HList
170166
* @see Tuple6
171167
*/
172-
@SuppressWarnings("JavaDoc")
173168
public static <_1, _2, _3, _4, _5, _6> Tuple6<_1, _2, _3, _4, _5, _6> tuple(_1 _1, _2 _2, _3 _3, _4 _4, _5 _5,
174169
_6 _6) {
175170
return tuple(_2, _3, _4, _5, _6).cons(_1);
@@ -195,7 +190,6 @@ public static <_1, _2, _3, _4, _5, _6> Tuple6<_1, _2, _3, _4, _5, _6> tuple(_1 _
195190
* @return the 7-element HList
196191
* @see Tuple7
197192
*/
198-
@SuppressWarnings("JavaDoc")
199193
public static <_1, _2, _3, _4, _5, _6, _7> Tuple7<_1, _2, _3, _4, _5, _6, _7> tuple(_1 _1, _2 _2, _3 _3, _4 _4,
200194
_5 _5, _6 _6, _7 _7) {
201195
return tuple(_2, _3, _4, _5, _6, _7).cons(_1);
@@ -223,7 +217,6 @@ public static <_1, _2, _3, _4, _5, _6, _7> Tuple7<_1, _2, _3, _4, _5, _6, _7> tu
223217
* @return the 8-element HList
224218
* @see Tuple8
225219
*/
226-
@SuppressWarnings("JavaDoc")
227220
public static <_1, _2, _3, _4, _5, _6, _7, _8> Tuple8<_1, _2, _3, _4, _5, _6, _7, _8> tuple(_1 _1, _2 _2, _3 _3,
228221
_4 _4, _5 _5, _6 _6,
229222
_7 _7, _8 _8) {
@@ -273,7 +266,7 @@ public final boolean equals(Object other) {
273266
if (other instanceof HCons) {
274267
HCons<?, ?> that = (HCons<?, ?>) other;
275268
return this.head.equals(that.head)
276-
&& this.tail.equals(that.tail);
269+
&& this.tail.equals(that.tail);
277270
}
278271
return false;
279272
}
@@ -297,16 +290,5 @@ private HNil() {
297290
public <Head> SingletonHList<Head> cons(Head head) {
298291
return new SingletonHList<>(head);
299292
}
300-
301-
/**
302-
* Snoc an element onto the back of this HList.
303-
*
304-
* @param last the new last element
305-
* @param <Last> the new last element type
306-
* @return the updated HList
307-
*/
308-
public <Last> SingletonHList<Last> snoc(Last last) {
309-
return new SingletonHList<>(last);
310-
}
311293
}
312294
}

src/main/java/com/jnape/palatable/lambda/adt/hlist/SingletonHList.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ public <_0> Tuple2<_0, _1> cons(_0 _0) {
4141

4242

4343
/**
44-
* Snoc an element onto the back of this HList.
44+
* Snoc an element onto the back of this {@link SingletonHList}.
4545
*
4646
* @param _2 the new last element
47-
* @return the updated HList
47+
* @param <_2> the new last element type
48+
* @return the new {@link Tuple2}
4849
*/
4950
public <_2> Tuple2<_1, _2> snoc(_2 _2) {
5051
return tuple(head(), _2);

src/main/java/com/jnape/palatable/lambda/adt/hlist/Tuple2.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class Tuple2<_1, _2> extends HCons<_1, SingletonHList<_2>> implements
4848
Tuple2(_1 _1, SingletonHList<_2> tail) {
4949
super(_1, tail);
5050
this._1 = _1;
51-
_2 = tail.head();
51+
_2 = tail.head();
5252
}
5353

5454
/**
@@ -76,10 +76,11 @@ public <_0> Tuple3<_0, _1, _2> cons(_0 _0) {
7676
}
7777

7878
/**
79-
* Snoc an element onto the back of this HList.
79+
* Snoc an element onto the back of this {@link Tuple2}.
8080
*
8181
* @param _3 the new last element
82-
* @return the updated HList
82+
* @param <_3> the new last element type
83+
* @return the new {@link Tuple3}
8384
*/
8485
public <_3> Tuple3<_1, _2, _3> snoc(_3 _3) {
8586
return tuple(_1, _2, _3);

src/main/java/com/jnape/palatable/lambda/adt/hlist/Tuple3.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public class Tuple3<_1, _2, _3> extends HCons<_1, Tuple2<_2, _3>> implements
4444
Tuple3(_1 _1, Tuple2<_2, _3> tail) {
4545
super(_1, tail);
4646
this._1 = _1;
47-
_2 = tail._1();
48-
_3 = tail._2();
47+
_2 = tail._1();
48+
_3 = tail._2();
4949
}
5050

5151
/**
@@ -57,10 +57,11 @@ public <_0> Tuple4<_0, _1, _2, _3> cons(_0 _0) {
5757
}
5858

5959
/**
60-
* Snoc an element onto the back of this HList.
60+
* Snoc an element onto the back of this {@link Tuple3}.
6161
*
6262
* @param _4 the new last element
63-
* @return the updated HList
63+
* @param <_4> the new last element type
64+
* @return the new {@link Tuple4}
6465
*/
6566
public <_4> Tuple4<_1, _2, _3, _4> snoc(_4 _4) {
6667
return tuple(_1, _2, _3, _4);

src/main/java/com/jnape/palatable/lambda/adt/hlist/Tuple4.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ public class Tuple4<_1, _2, _3, _4> extends HCons<_1, Tuple3<_2, _3, _4>> implem
4646
Tuple4(_1 _1, Tuple3<_2, _3, _4> tail) {
4747
super(_1, tail);
4848
this._1 = _1;
49-
_2 = tail._1();
50-
_3 = tail._2();
51-
_4 = tail._3();
49+
_2 = tail._1();
50+
_3 = tail._2();
51+
_4 = tail._3();
5252
}
5353

5454
/**
@@ -60,10 +60,11 @@ public <_0> Tuple5<_0, _1, _2, _3, _4> cons(_0 _0) {
6060
}
6161

6262
/**
63-
* Snoc an element onto the back of this HList.
63+
* Snoc an element onto the back of this {@link Tuple4}.
6464
*
6565
* @param _5 the new last element
66-
* @return the updated HList
66+
* @param <_5> the new last element type
67+
* @return the new {@link Tuple5}
6768
*/
6869
public <_5> Tuple5<_1, _2, _3, _4, _5> snoc(_5 _5) {
6970
return tuple(_1, _2, _3, _4, _5);

src/main/java/com/jnape/palatable/lambda/adt/hlist/Tuple5.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ public class Tuple5<_1, _2, _3, _4, _5> extends HCons<_1, Tuple4<_2, _3, _4, _5>
4848
Tuple5(_1 _1, Tuple4<_2, _3, _4, _5> tail) {
4949
super(_1, tail);
5050
this._1 = _1;
51-
_2 = tail._1();
52-
_3 = tail._2();
53-
_4 = tail._3();
54-
_5 = tail._4();
51+
_2 = tail._1();
52+
_3 = tail._2();
53+
_4 = tail._3();
54+
_5 = tail._4();
5555
}
5656

5757
/**
@@ -63,10 +63,11 @@ public <_0> Tuple6<_0, _1, _2, _3, _4, _5> cons(_0 _0) {
6363
}
6464

6565
/**
66-
* Snoc an element onto the back of this HList.
66+
* Snoc an element onto the back of this {@link Tuple5}.
6767
*
6868
* @param _6 the new last element
69-
* @return the updated HList
69+
* @param <_6> the new last element type
70+
* @return the new {@link Tuple6}
7071
*/
7172
public <_6> Tuple6<_1, _2, _3, _4, _5, _6> snoc(_6 _6) {
7273
return tuple(_1, _2, _3, _4, _5, _6);

src/main/java/com/jnape/palatable/lambda/adt/hlist/Tuple6.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ public class Tuple6<_1, _2, _3, _4, _5, _6> extends HCons<_1, Tuple5<_2, _3, _4,
5151
Tuple6(_1 _1, Tuple5<_2, _3, _4, _5, _6> tail) {
5252
super(_1, tail);
5353
this._1 = _1;
54-
_2 = tail._1();
55-
_3 = tail._2();
56-
_4 = tail._3();
57-
_5 = tail._4();
58-
_6 = tail._5();
54+
_2 = tail._1();
55+
_3 = tail._2();
56+
_4 = tail._3();
57+
_5 = tail._4();
58+
_6 = tail._5();
5959
}
6060

6161
/**
@@ -67,10 +67,11 @@ public <_0> Tuple7<_0, _1, _2, _3, _4, _5, _6> cons(_0 _0) {
6767
}
6868

6969
/**
70-
* Snoc an element onto the back of this HList.
70+
* Snoc an element onto the back of this {@link Tuple6}.
7171
*
7272
* @param _7 the new last element
73-
* @return the updated HList
73+
* @param <_7> the new last element type
74+
* @return the new {@link Tuple7}
7475
*/
7576
public <_7> Tuple7<_1, _2, _3, _4, _5, _6, _7> snoc(_7 _7) {
7677
return tuple(_1, _2, _3, _4, _5, _6, _7);

src/main/java/com/jnape/palatable/lambda/adt/hlist/Tuple7.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ public class Tuple7<_1, _2, _3, _4, _5, _6, _7> extends HCons<_1, Tuple6<_2, _3,
5454
Tuple7(_1 _1, Tuple6<_2, _3, _4, _5, _6, _7> tail) {
5555
super(_1, tail);
5656
this._1 = _1;
57-
_2 = tail._1();
58-
_3 = tail._2();
59-
_4 = tail._3();
60-
_5 = tail._4();
61-
_6 = tail._5();
62-
_7 = tail._6();
57+
_2 = tail._1();
58+
_3 = tail._2();
59+
_4 = tail._3();
60+
_5 = tail._4();
61+
_6 = tail._5();
62+
_7 = tail._6();
6363
}
6464

6565
/**
@@ -71,10 +71,11 @@ public <_0> Tuple8<_0, _1, _2, _3, _4, _5, _6, _7> cons(_0 _0) {
7171
}
7272

7373
/**
74-
* Snoc an element onto the back of this HList.
74+
* Snoc an element onto the back of this {@link Tuple7}.
7575
*
7676
* @param _8 the new last element
77-
* @return the updated HList
77+
* @param <_8> the new last element type
78+
* @return the new {@link Tuple8}
7879
*/
7980
public <_8> Tuple8<_1, _2, _3, _4, _5, _6, _7, _8> snoc(_8 _8) {
8081
return tuple(_1, _2, _3, _4, _5, _6, _7, _8);

src/main/java/com/jnape/palatable/lambda/adt/hlist/Tuple8.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ public class Tuple8<_1, _2, _3, _4, _5, _6, _7, _8> extends HCons<_1, Tuple7<_2,
5757
Tuple8(_1 _1, Tuple7<_2, _3, _4, _5, _6, _7, _8> tail) {
5858
super(_1, tail);
5959
this._1 = _1;
60-
_2 = tail._1();
61-
_3 = tail._2();
62-
_4 = tail._3();
63-
_5 = tail._4();
64-
_6 = tail._5();
65-
_7 = tail._6();
66-
_8 = tail._7();
60+
_2 = tail._1();
61+
_3 = tail._2();
62+
_4 = tail._3();
63+
_5 = tail._4();
64+
_6 = tail._5();
65+
_7 = tail._6();
66+
_8 = tail._7();
6767
}
6868

6969
/**
@@ -75,10 +75,11 @@ public <_0> HCons<_0, Tuple8<_1, _2, _3, _4, _5, _6, _7, _8>> cons(_0 _0) {
7575
}
7676

7777
/**
78-
* Snoc an element onto the back of this HList.
78+
* Snoc an element onto the back of this {@link Tuple8}.
7979
*
8080
* @param _9 the new last element
81-
* @return the updated HList
81+
* @param <_9> the new last element type
82+
* @return the new {@link HCons consed} {@link Tuple8}
8283
*/
8384
public <_9> HCons<_1, Tuple8<_2, _3, _4, _5, _6, _7, _8, _9>> snoc(_9 _9) {
8485
return singletonHList(_9).cons(_8).cons(_7).cons(_6).cons(_5).cons(_4).cons(_3).cons(_2).cons(_1);

src/test/java/com/jnape/palatable/lambda/adt/hlist/HListTest.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22

33
import org.junit.Test;
44

5-
import static com.jnape.palatable.lambda.adt.hlist.HList.*;
5+
import static com.jnape.palatable.lambda.adt.hlist.HList.cons;
6+
import static com.jnape.palatable.lambda.adt.hlist.HList.nil;
7+
import static com.jnape.palatable.lambda.adt.hlist.HList.singletonHList;
8+
import static com.jnape.palatable.lambda.adt.hlist.HList.tuple;
69
import static org.hamcrest.CoreMatchers.instanceOf;
7-
import static org.junit.Assert.*;
10+
import static org.junit.Assert.assertEquals;
11+
import static org.junit.Assert.assertNotEquals;
12+
import static org.junit.Assert.assertSame;
13+
import static org.junit.Assert.assertThat;
814

915
public class HListTest {
1016

@@ -48,16 +54,15 @@ public void nilReusesInstance() {
4854
}
4955

5056
@Test
51-
@SuppressWarnings({"EqualsWithItself", "EqualsBetweenInconvertibleTypes"})
5257
public void equality() {
53-
assertTrue(nil().equals(nil()));
54-
assertTrue(cons(1, nil()).equals(cons(1, nil())));
58+
assertEquals(nil(), nil());
59+
assertEquals(cons(1, nil()), cons(1, nil()));
5560

56-
assertFalse(cons(1, nil()).equals(nil()));
57-
assertFalse(nil().equals(cons(1, nil())));
61+
assertNotEquals(cons(1, nil()), nil());
62+
assertNotEquals(nil(), cons(1, nil()));
5863

59-
assertFalse(cons(1, cons(2, nil())).equals(cons(1, nil())));
60-
assertFalse(cons(1, nil()).equals(cons(1, cons(2, nil()))));
64+
assertNotEquals(cons(1, cons(2, nil())), cons(1, nil()));
65+
assertNotEquals(cons(1, nil()), cons(1, cons(2, nil())));
6166
}
6267

6368
@Test
@@ -68,10 +73,4 @@ public void hashCodeUsesDecentDistribution() {
6873
assertNotEquals(nil().cons(1).hashCode(), nil().cons(2).hashCode());
6974
assertNotEquals(nil().cons(1).cons(2).hashCode(), nil().cons(1).cons(3).hashCode());
7075
}
71-
72-
@Test
73-
public void snoc() {
74-
SingletonHList<Float> tuple = nil().snoc((float) 4.0);
75-
assertEquals(4.0, tuple.head(), 0.01);
76-
}
7776
}

src/test/java/com/jnape/palatable/lambda/adt/hlist/SingletonHListTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public void cons() {
4747
assertEquals(new Tuple2<>("0", singletonHList), singletonHList.cons("0"));
4848
}
4949

50+
@Test
51+
public void snoc() {
52+
assertEquals(tuple((byte) 127, 'x'), singletonHList((byte) 127).snoc('x'));
53+
}
54+
5055
@Test
5156
public void intoAppliesHeadToFn() {
5257
assertEquals("FOO", singletonHList("foo").into(String::toUpperCase));
@@ -57,10 +62,4 @@ public void staticPure() {
5762
SingletonHList<Integer> singletonHList = pureSingletonHList().apply(1);
5863
assertEquals(singletonHList(1), singletonHList);
5964
}
60-
61-
@Test
62-
public void snoc() {
63-
Tuple2<Byte, Character> tuple = singletonHList((byte) 127).snoc('x');
64-
assertEquals(tuple((byte) 127, 'x'), tuple);
65-
}
6665
}

src/test/java/com/jnape/palatable/lambda/adt/hlist/Tuple2Test.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ public void cons() {
6868
assertEquals(new Tuple3<>(0, tuple2), tuple2.cons(0));
6969
}
7070

71+
@Test
72+
public void snoc() {
73+
assertEquals(tuple(Long.MAX_VALUE, 123, "hi"), tuple(Long.MAX_VALUE, 123).snoc("hi"));
74+
}
75+
7176
@Test
7277
public void accessors() {
7378
assertEquals((Integer) 1, tuple2._1());
@@ -143,10 +148,4 @@ public void staticPure() {
143148
Tuple2<Integer, String> tuple = pureTuple(1).apply("two");
144149
assertEquals(tuple(1, "two"), tuple);
145150
}
146-
147-
@Test
148-
public void snoc() {
149-
Tuple3<Long, Integer, String> tuple = tuple(Long.MAX_VALUE, 123).snoc("hi");
150-
assertEquals(tuple(Long.MAX_VALUE, 123, "hi"), tuple);
151-
}
152151
}

0 commit comments

Comments
 (0)