Skip to content

Commit 187ac4e

Browse files
committed
Making Over/Set/View use singleton instances; adding test for TypeSafeKey
1 parent c478604 commit 187ac4e

File tree

5 files changed

+26
-4
lines changed

5 files changed

+26
-4
lines changed

src/main/java/com/jnape/palatable/lambda/adt/hmap/TypeSafeKey.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
*
1111
* @param <T> The type of the value that this key maps to inside an HMap
1212
*/
13-
@SuppressWarnings("unused")
1413
public interface TypeSafeKey<T> {
1514

1615
/**

src/main/java/com/jnape/palatable/lambda/lens/functions/Over.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
*/
2626
public final class Over<S, T, A, B> implements Fn3<Lens<S, T, A, B>, Function<? super A, ? extends B>, S, T> {
2727

28+
private static final Over INSTANCE = new Over();
29+
2830
private Over() {
2931
}
3032

@@ -35,8 +37,9 @@ public T apply(Lens<S, T, A, B> lens, Function<? super A, ? extends B> fn, S s)
3537
.runIdentity();
3638
}
3739

40+
@SuppressWarnings("unchecked")
3841
public static <S, T, A, B> Over<S, T, A, B> over() {
39-
return new Over<>();
42+
return (Over<S, T, A, B>) INSTANCE;
4043
}
4144

4245
public static <S, T, A, B> Fn2<Function<? super A, ? extends B>, S, T> over(

src/main/java/com/jnape/palatable/lambda/lens/functions/Set.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
*/
2626
public final class Set<S, T, A, B> implements Fn3<Lens<S, T, A, B>, B, S, T> {
2727

28+
private static final Set INSTANCE = new Set();
29+
2830
private Set() {
2931
}
3032

@@ -33,8 +35,9 @@ public T apply(Lens<S, T, A, B> lens, B b, S s) {
3335
return over(lens, constantly(b), s);
3436
}
3537

38+
@SuppressWarnings("unchecked")
3639
public static <S, T, A, B> Set<S, T, A, B> set() {
37-
return new Set<>();
40+
return INSTANCE;
3841
}
3942

4043
public static <S, T, A, B> Fn2<B, S, T> set(Lens<S, T, A, B> lens) {

src/main/java/com/jnape/palatable/lambda/lens/functions/View.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
*/
2121
public final class View<S, T, A, B> implements Fn2<Lens<S, T, A, B>, S, A> {
2222

23+
private static final View INSTANCE = new View();
24+
2325
private View() {
2426
}
2527

@@ -28,8 +30,9 @@ public A apply(Lens<S, T, A, B> lens, S s) {
2830
return lens.<Const<A, T>, Const<A, B>>fix().apply(Const::new, s).runConst();
2931
}
3032

33+
@SuppressWarnings("unchecked")
3134
public static <S, T, A, B> View<S, T, A, B> view() {
32-
return new View<>();
35+
return INSTANCE;
3336
}
3437

3538
public static <S, T, A, B> Fn1<S, A> view(Lens<S, T, A, B> lens) {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.jnape.palatable.lambda.adt.hmap;
2+
3+
import org.junit.Test;
4+
5+
import static com.jnape.palatable.lambda.adt.hmap.TypeSafeKey.typeSafeKey;
6+
import static org.junit.Assert.assertFalse;
7+
8+
public class TypeSafeKeyTest {
9+
10+
@Test
11+
public void usesReferenceEquality() {
12+
assertFalse(typeSafeKey().equals(typeSafeKey()));
13+
}
14+
}

0 commit comments

Comments
 (0)