Skip to content

Commit b438b1b

Browse files
committed
Converted anonymous F2 classes to use lambdas
1 parent 0ca5248 commit b438b1b

File tree

17 files changed

+23
-105
lines changed

17 files changed

+23
-105
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,7 @@ public A sumRight(final List<A> as) {
118118
* @return The sum of the given values.
119119
*/
120120
public A sumRight(final Stream<A> as) {
121-
return as.foldRight(new F2<A, P1<A>, A>() {
122-
public A f(final A a, final P1<A> ap1) {
123-
return sum(a, ap1._1());
124-
}
125-
}, zero);
121+
return as.foldRight((a, ap1) -> sum(a, ap1._1()), zero);
126122
}
127123

128124
/**

core/src/main/java/fj/control/parallel/Promise.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,7 @@ public <B, C> Promise<C> bind(final P1<Promise<B>> p, final F<A, F<B, C>> f) {
222222
* @return A function of arity-2 promoted to map over promises.
223223
*/
224224
public static <A, B, C> F<Promise<A>, F<Promise<B>, Promise<C>>> liftM2(final F<A, F<B, C>> f) {
225-
return curry(new F2<Promise<A>, Promise<B>, Promise<C>>() {
226-
public Promise<C> f(final Promise<A> ca, final Promise<B> cb) {
227-
return ca.bind(cb, f);
228-
}
229-
});
225+
return curry((ca, cb) -> ca.bind(cb, f));
230226
}
231227

232228
/**

core/src/main/java/fj/data/Array.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -600,11 +600,7 @@ public static <A> F<A[], Array<A>> wrap() {
600600
* @return A function that maps a given function across a given array.
601601
*/
602602
public static <A, B> F<F<A, B>, F<Array<A>, Array<B>>> map() {
603-
return curry(new F2<F<A, B>, Array<A>, Array<B>>() {
604-
public Array<B> f(final F<A, B> abf, final Array<A> array) {
605-
return array.map(abf);
606-
}
607-
});
603+
return curry((abf, array) -> array.map(abf));
608604
}
609605

610606
/**

core/src/main/java/fj/data/Enumerator.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,7 @@ public static <A> Enumerator<A> enumerator(final F<A, Option<A>> successor, fina
236236
*/
237237
public static <A> Enumerator<A> enumerator(final F<A, Option<A>> successor, final F<A, Option<A>> predecessor,
238238
final Option<A> max, final Option<A> min, final Ord<A> order) {
239-
return new Enumerator<A>(successor, predecessor, max, min, order, curry(new F2<A, Long, Option<A>>() {
240-
public Option<A> f(final A a, final Long l) {
239+
return new Enumerator<A>(successor, predecessor, max, min, order, curry((a, l) -> {
241240
if (l == 0L)
242241
return some(a);
243242
else if (l < 0L) {
@@ -261,7 +260,6 @@ else if (l < 0L) {
261260
}
262261
return some(aa);
263262
}
264-
}
265263
}));
266264
}
267265

core/src/main/java/fj/data/Option.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -512,11 +512,7 @@ public final <X> Validation<X, A> toValidation(final X x) {
512512
* return in left.
513513
*/
514514
public static <A, X> F<Option<A>, F<X, Either<X, A>>> toEither() {
515-
return curry(new F2<Option<A>, X, Either<X, A>>() {
516-
public Either<X, A> f(final Option<A> a, final X x) {
517-
return a.toEither(x);
518-
}
519-
});
515+
return curry((a, x) -> a.toEither(x));
520516
}
521517

522518
/**

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,7 @@ public abstract <B> B match(final F<One<V, A>, B> one, final F<Two<V, A>, B> two
121121
* @return the sum of the measurements of this digit according to the monoid.
122122
*/
123123
public final V measure() {
124-
return foldLeft(Function.curry(new F2<V, A, V>() {
125-
public V f(final V v, final A a) {
126-
return m.sum(v, m.measure(a));
127-
}
128-
}), m.zero());
124+
return foldLeft(Function.curry((v, a) -> m.sum(v, m.measure(a))), m.zero());
129125
}
130126

131127
/**

core/src/main/java/fj/data/fingertrees/Node.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,11 @@ public abstract class Node<V, A> {
2020
public abstract <B> B foldLeft(final F<B, F<A, B>> f, final B z);
2121

2222
public static <V, A, B> F<B, F<Node<V, A>, B>> foldLeft_(final F<B, F<A, B>> bff) {
23-
return curry(new F2<B, Node<V, A>, B>() {
24-
public B f(final B b, final Node<V, A> node) { return node.foldLeft(bff, b); }
25-
});
23+
return curry((b, node) -> node.foldLeft(bff, b));
2624
}
2725

2826
public static <V, A, B> F<B, F<Node<V, A>, B>> foldRight_(final F<A, F<B, B>> aff) {
29-
return curry(new F2<B, Node<V, A>, B>() {
30-
public B f(final B b, final Node<V, A> node) { return node.foldRight(aff, b); }
31-
});
27+
return curry((b, node) -> node.foldRight(aff, b));
3228
}
3329

3430
public final <B> Node<V, B> map(final F<A, B> f, final Measured<V, B> m) {

core/src/main/java/fj/data/hlist/HList.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,7 @@ public C append(final A a, final B b) {
9191
* @return a method for concatenating lists to the empty list.
9292
*/
9393
public static <L extends HList<L>> HAppend<HNil, L, L> append() {
94-
return new HAppend<HNil, L, L>(new F2<HNil, L, L>() {
95-
public L f(final HNil hNil, final L l) {
96-
return l;
97-
}
98-
});
94+
return new HAppend<HNil, L, L>((hNil, l) -> l);
9995
}
10096

10197
/**
@@ -106,11 +102,7 @@ public L f(final HNil hNil, final L l) {
106102
*/
107103
public static <X, A extends HList<A>, B, C extends HList<C>, H extends HAppend<A, B, C>>
108104
HAppend<HCons<X, A>, B, HCons<X, C>> append(final H h) {
109-
return new HAppend<HCons<X, A>, B, HCons<X, C>>(new F2<HCons<X, A>, B, HCons<X, C>>() {
110-
public HCons<X, C> f(final HCons<X, A> c, final B l) {
111-
return cons(c.head(), h.append(c.tail(), l));
112-
}
113-
});
105+
return new HAppend<HCons<X, A>, B, HCons<X, C>>((c, l) -> cons(c.head(), h.append(c.tail(), l)));
114106
}
115107
}
116108

core/src/main/java/fj/function/Integers.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,7 @@ private Integers() {
3737
/**
3838
* Curried Integer subtraction.
3939
*/
40-
public static final F<Integer, F<Integer, Integer>> subtract = curry(new F2<Integer, Integer, Integer>() {
41-
public Integer f(final Integer x, final Integer y) {
42-
return x - y;
43-
}
44-
});
40+
public static final F<Integer, F<Integer, Integer>> subtract = curry((x, y) -> x - y);
4541

4642
/**
4743
* Negation.

core/src/main/java/fj/function/Visitor.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,7 @@ public static <A, B> B nullableVisitor(final List<F<A, B>> visitors, final F0<B>
8383
* @return A function that can be applied to a default value (there is no association) and an associated key.
8484
*/
8585
public static <A, B> F<B, F<A, B>> association(final List<P2<A, B>> x, final Equal<A> eq) {
86-
return curry(new F2<B, A, B>() {
87-
public B f(final B def, final A a) {
88-
return lookup(eq, x, a).orSome(def);
89-
}
90-
});
86+
return curry((def, a) -> lookup(eq, x, a).orSome(def));
9187
}
9288

9389
/**
@@ -99,10 +95,6 @@ public B f(final B def, final A a) {
9995
* @return A function that can be applied to a default value (there is no association) and an associated key.
10096
*/
10197
public static <A, B> F<P1<B>, F<A, B>> associationLazy(final List<P2<A, B>> x, final Equal<A> eq) {
102-
return curry(new F2<P1<B>, A, B>() {
103-
public B f(final P1<B> def, final A a) {
104-
return lookup(eq, x, a).orSome(def);
105-
}
106-
});
98+
return curry((def, a) -> lookup(eq, x, a).orSome(def));
10799
}
108100
}

0 commit comments

Comments
 (0)