Skip to content

Commit a93c54c

Browse files
committed
Use lambda syntax instead of anonymous class whenever possible
1 parent 316d1d4 commit a93c54c

File tree

23 files changed

+640
-1839
lines changed

23 files changed

+640
-1839
lines changed

core/src/main/java/fj/control/Trampoline.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,14 @@ public <B> Trampoline<B> bind(final F<A, Trampoline<B>> f) {
5252
// The resumption of a Codense is the resumption of its subcomputation. If that computation is done, its result
5353
// gets shifted into the continuation.
5454
public Either<P1<Trampoline<A>>, A> resume() {
55-
return left(sub.resume().either(p -> {
56-
return p.map(ot -> {
57-
// WARNING: In JDK 8, update 25 (current version) the following code is a
58-
// workaround for an internal JDK compiler error, likely due to
59-
// https:bugs.openjdk.java.net/browse/JDK-8062253.
60-
F<Normal<Object>, Trampoline<A>> f = o -> o.foldNormal(cont::f, t -> t._1().bind(cont));
61-
F<Codense<Object>, Trampoline<A>> g = c -> codense(c.sub, o -> c.cont.f(o).bind(cont));
62-
return ot.fold(f, g);
63-
});
64-
}, o -> P.lazy(() -> cont.f(o))));
55+
return left(sub.resume().either(p -> p.map(ot -> {
56+
// WARNING: In JDK 8, update 25 (current version) the following code is a
57+
// workaround for an internal JDK compiler error, likely due to
58+
// https:bugs.openjdk.java.net/browse/JDK-8062253.
59+
F<Normal<Object>, Trampoline<A>> f = o -> o.foldNormal(cont::f, t -> t._1().bind(cont));
60+
F<Codense<Object>, Trampoline<A>> g = c -> codense(c.sub, o -> c.cont.f(o).bind(cont));
61+
return ot.fold(f, g);
62+
}), o -> P.lazy(() -> cont.f(o))));
6563
}
6664
}
6765

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,12 @@ public static <A> F<Callable<A>, P1<Either<Exception, A>>> either() {
216216
* @return A Callable equivalent to the given Either value.
217217
*/
218218
public static <A> Callable<A> fromEither(final F0<Either<Exception, A>> e) {
219-
return new Callable<A>() {
220-
public A call() throws Exception {
221-
final Either<Exception, A> e1 = e.f();
222-
if (e1.isLeft())
223-
throw e1.left().value();
224-
else
225-
return e1.right().value();
226-
}
219+
return () -> {
220+
final Either<Exception, A> e1 = e.f();
221+
if (e1.isLeft())
222+
throw e1.left().value();
223+
else
224+
return e1.right().value();
227225
};
228226
}
229227

@@ -243,14 +241,12 @@ public static <A> F<P1<Either<Exception, A>>, Callable<A>> fromEither() {
243241
* @return A Callable that yields some value or throws an exception in the case of no value.
244242
*/
245243
public static <A> Callable<A> fromOption(final F0<Option<A>> o) {
246-
return new Callable<A>() {
247-
public A call() throws Exception {
248-
final Option<A> o1 = o.f();
249-
if (o1.isSome())
250-
return o1.some();
251-
else
252-
throw new Exception("No value.");
253-
}
244+
return () -> {
245+
final Option<A> o1 = o.f();
246+
if (o1.isSome())
247+
return o1.some();
248+
else
249+
throw new Exception("No value.");
254250
};
255251
}
256252

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,7 @@ public static <A> P1<A> obtain(final Future<A> t) {
339339
* @return An effect, which, given a Future, waits for it to obtain a value, discarding the value.
340340
*/
341341
public static <A> Effect1<Future<A>> discard() {
342-
return a -> {
343-
Strategy.<A>obtain().f(a)._1();
344-
};
342+
return a -> Strategy.<A>obtain().f(a)._1();
345343
}
346344

347345
/**

0 commit comments

Comments
 (0)