Skip to content

Commit 316d1d4

Browse files
committed
Use method reference (over lambda) whenever possible
1 parent a069fa5 commit 316d1d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+514
-726
lines changed

core/src/main/java/fj/Bottom.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public static <A> Error decons(final java.lang.Class<A> c) {
8383
* @return A function that returns the <code>toString</code> for a throwable.
8484
*/
8585
public static <T extends Throwable> F<T, String> eToString() {
86-
return t -> t.toString();
86+
return Throwable::toString;
8787
}
8888

8989
/**
@@ -92,6 +92,6 @@ public static <T extends Throwable> F<T, String> eToString() {
9292
* @return A function that returns the <code>getMessage</code> for a throwable.
9393
*/
9494
public static <T extends Throwable> F<T, String> eMessage() {
95-
return t -> t.getMessage();
95+
return Throwable::getMessage;
9696
}
9797
}

core/src/main/java/fj/Class.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public java.lang.Class<? super T> _2() {
4545
};
4646
return some(p);
4747
}
48-
}, c).map(c1 -> clas(c1));
48+
}, c).map(Class::clas);
4949
}
5050

5151
/**

core/src/main/java/fj/Digit.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,20 +176,20 @@ public static Option<Digit> fromChar(final char c) {
176176
/**
177177
* First-class conversion from digit to a long.
178178
*/
179-
public static final F<Digit, Long> toLong = d -> d.toLong();
179+
public static final F<Digit, Long> toLong = Digit::toLong;
180180

181181
/**
182182
* First-class conversion from a long to a digit.
183183
*/
184-
public static final F<Long, Digit> fromLong = i -> fromLong(i);
184+
public static final F<Long, Digit> fromLong = Digit::fromLong;
185185

186186
/**
187187
* First-class conversion from a digit to a character.
188188
*/
189-
public static final F<Digit, Character> toChar = d -> d.toChar();
189+
public static final F<Digit, Character> toChar = Digit::toChar;
190190

191191
/**
192192
* First-class conversion from a character to a digit.
193193
*/
194-
public static final F<Character, Option<Digit>> fromChar = c -> fromChar(c);
194+
public static final F<Character, Option<Digit>> fromChar = Digit::fromChar;
195195
}

core/src/main/java/fj/Effect.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public static <A, B> Effect1<B> contramap(Effect1<A> e1, final F<B, A> f) {
100100
}
101101

102102
public static <A> Effect1<A> lazy(final F<A, Unit> f) {
103-
return a -> f.f(a);
103+
return f::f;
104104

105105
}
106106

core/src/main/java/fj/Equal.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public boolean notEq(final A a1, final A a2) {
5555
* @return A function that returns <code>true</code> if the two given arguments are equal.
5656
*/
5757
public F2<A, A, Boolean> eq() {
58-
return (a, a1) -> eq(a, a1);
58+
return this::eq;
5959
}
6060

6161
/**
@@ -96,7 +96,7 @@ public static <A> Equal<A> equal(final F<A, F<A, Boolean>> f) {
9696
* equality.
9797
*/
9898
public static <A> Equal<A> anyEqual() {
99-
return equal(a1 -> a2 -> a1.equals(a2));
99+
return equal(a1 -> a1::equals);
100100
}
101101

102102
/**

core/src/main/java/fj/Function.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public static <A> F<A, A> identity() {
8989
* @return A function that given an argument, returns a function that ignores its argument.
9090
*/
9191
public static <A, B> F<B, F<A, B>> constant() {
92-
return b -> constant(b);
92+
return Function::constant;
9393
}
9494

9595
/**
@@ -109,7 +109,7 @@ public static <A, B> F<A, B> constant(final B b) {
109109
* @return A co- and contravariant function that invokes f on its argument.
110110
*/
111111
public static <A, B> F<A, B> vary(final F<? super A, ? extends B> f) {
112-
return a -> f.f(a);
112+
return f::f;
113113
}
114114

115115
/**
@@ -118,7 +118,7 @@ public static <A, B> F<A, B> vary(final F<? super A, ? extends B> f) {
118118
* @return A function that varies and covaries a function.
119119
*/
120120
public static <C, A extends C, B, D extends B> F<F<C, D>, F<A, B>> vary() {
121-
return f -> Function.<A, B>vary(f);
121+
return Function::<A, B>vary;
122122
}
123123

124124
/**
@@ -127,7 +127,7 @@ public static <C, A extends C, B, D extends B> F<F<C, D>, F<A, B>> vary() {
127127
* @return A function that takes a function and flips its arguments.
128128
*/
129129
public static <A, B, C> F<F<A, F<B, C>>, F<B, F<A, C>>> flip() {
130-
return f -> flip(f);
130+
return Function::flip;
131131
}
132132

133133
/**
@@ -156,7 +156,7 @@ public static <A, B, C> F2<B, A, C> flip(final F2<A, B, C> f) {
156156
* @return A function that flips the arguments of a given function.
157157
*/
158158
public static <A, B, C> F<F2<A, B, C>, F2<B, A, C>> flip2() {
159-
return f -> flip(f);
159+
return Function::flip;
160160
}
161161

162162
/**
@@ -198,7 +198,7 @@ public static <A, B, C> F<B, C> curry(final F2<A, B, C> f, final A a) {
198198
* @return An uncurried function.
199199
*/
200200
public static <A, B, C> F<F<A, F<B, C>>, F2<A, B, C>> uncurryF2() {
201-
return f -> uncurryF2(f);
201+
return Function::uncurryF2;
202202
}
203203

204204
/**
@@ -250,7 +250,7 @@ public static <A, B, C, D> F<C, D> curry(final F3<A, B, C, D> f, final A a, fina
250250
* @return An uncurried function.
251251
*/
252252
public static <A, B, C, D> F<F<A, F<B, F<C, D>>>, F3<A, B, C, D>> uncurryF3() {
253-
return f -> uncurryF3(f);
253+
return Function::uncurryF3;
254254
}
255255

256256
/**
@@ -315,7 +315,7 @@ public static <A, B, C, D, E> F<D, E> curry(final F4<A, B, C, D, E> f, final A a
315315
* @return An uncurried function.
316316
*/
317317
public static <A, B, C, D, E> F<F<A, F<B, F<C, F<D, E>>>>, F4<A, B, C, D, E>> uncurryF4() {
318-
return f -> uncurryF4(f);
318+
return Function::uncurryF4;
319319
}
320320

321321
/**
@@ -396,7 +396,7 @@ public static <A, B, C, D, E> F4<A, B, C, D, E> uncurryF4(final F<A, F<B, F<C, F
396396
* @return An uncurried function.
397397
*/
398398
public static <A, B, C, D, E, F$> F<F<A, F<B, F<C, F<D, F<E, F$>>>>>, F5<A, B, C, D, E, F$>> uncurryF5() {
399-
return f -> uncurryF5(f);
399+
return Function::uncurryF5;
400400
}
401401

402402
/**
@@ -425,7 +425,7 @@ public static <A, B, C, D, E> F4<A, B, C, D, E> uncurryF4(final F<A, F<B, F<C, F
425425
* @return An uncurried function.
426426
*/
427427
public static <A, B, C, D, E, F$, G> F<F<A, F<B, F<C, F<D, F<E, F<F$, G>>>>>>, F6<A, B, C, D, E, F$, G>> uncurryF6() {
428-
return f -> uncurryF6(f);
428+
return Function::uncurryF6;
429429
}
430430

431431
/**
@@ -543,7 +543,7 @@ public static <A, B, C, D, E> F4<A, B, C, D, E> uncurryF4(final F<A, F<B, F<C, F
543543
* @return An uncurried function.
544544
*/
545545
public static <A, B, C, D, E, F$, G, H> F<F<A, F<B, F<C, F<D, F<E, F<F$, F<G, H>>>>>>>, F7<A, B, C, D, E, F$, G, H>> uncurryF7() {
546-
return f -> uncurryF7(f);
546+
return Function::uncurryF7;
547547
}
548548

549549
/**
@@ -682,7 +682,7 @@ public static <A, B, C, D, E> F4<A, B, C, D, E> uncurryF4(final F<A, F<B, F<C, F
682682
* @return An uncurried function.
683683
*/
684684
public static <A, B, C, D, E, F$, G, H, I> F<F<A, F<B, F<C, F<D, F<E, F<F$, F<G, F<H, I>>>>>>>>, F8<A, B, C, D, E, F$, G, H, I>> uncurryF8() {
685-
return f -> uncurryF8(f);
685+
return Function::uncurryF8;
686686
}
687687

688688
/**

core/src/main/java/fj/Hash.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static <A> Hash<A> hash(final F<A, Integer> f) {
6262
* @return A hash that uses {@link Object#hashCode()}.
6363
*/
6464
public static <A> Hash<A> anyHash() {
65-
return hash(a -> a.hashCode());
65+
return hash(Object::hashCode);
6666
}
6767

6868
/**

core/src/main/java/fj/Monoid.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public A sumLeft(final Stream<A> as) {
156156
* @return a function that sums the given values with left-fold.
157157
*/
158158
public F<List<A>, A> sumLeft() {
159-
return as -> sumLeft(as);
159+
return this::sumLeft;
160160
}
161161

162162
/**
@@ -165,7 +165,7 @@ public F<List<A>, A> sumLeft() {
165165
* @return a function that sums the given values with right-fold.
166166
*/
167167
public F<List<A>, A> sumRight() {
168-
return as -> sumRight(as);
168+
return this::sumRight;
169169
}
170170

171171
/**
@@ -174,7 +174,7 @@ public F<List<A>, A> sumRight() {
174174
* @return a function that sums the given values with left-fold.
175175
*/
176176
public F<Stream<A>, A> sumLeftS() {
177-
return as -> sumLeft(as);
177+
return this::sumLeft;
178178
}
179179

180180
/**

core/src/main/java/fj/Ord.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,12 @@ public A min(final A a1, final A a2) {
150150
/**
151151
* A function that returns the greater of its two arguments.
152152
*/
153-
public final F<A, F<A, A>> max = curry((a, a1) -> max(a, a1));
153+
public final F<A, F<A, A>> max = curry(this::max);
154154

155155
/**
156156
* A function that returns the lesser of its two arguments.
157157
*/
158-
public final F<A, F<A, A>> min = curry((a, a1) -> min(a, a1));
158+
public final F<A, F<A, A>> min = curry(this::min);
159159

160160
public Ord<A> reverse() { return ord(Function.flip(f)); }
161161

@@ -428,7 +428,7 @@ public static <A> Ord<Array<A>> arrayOrd(final Ord<A> oa) {
428428
* @return An order instance for the {@link Set} type.
429429
*/
430430
public static <A> Ord<Set<A>> setOrd(final Ord<A> oa) {
431-
return streamOrd(oa).contramap(as -> as.toStream());
431+
return streamOrd(oa).contramap(Set::toStream);
432432
}
433433

434434
/**

core/src/main/java/fj/P.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ private P() {
1818
* @return A function that puts an element in a product-1.
1919
*/
2020
public static <A> F<A, P1<A>> p1() {
21-
return a -> p(a);
21+
return P::p;
2222
}
2323

2424
/**

0 commit comments

Comments
 (0)