Skip to content

Commit 254e3f5

Browse files
committed
Fixed code to not use Java 8 features
1 parent c07a58b commit 254e3f5

File tree

3 files changed

+39
-32
lines changed

3 files changed

+39
-32
lines changed

core/src/test/java/fj/control/parallel/StrategyTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import fj.P1;
66
import fj.Unit;
77
import fj.data.Enumerator;
8+
import fj.data.Java;
89
import fj.data.List;
910
import fj.data.Stream;
1011
import org.junit.Test;
@@ -49,10 +50,16 @@ public void testStrategyCompletion() {
4950
@Test
5051
public void testStrategyMergeAll() {
5152
final List<Integer> l = List.range(0, 100);
52-
final List<P1<Integer>> p1s = mergeAll(l.map(x -> CompletableFuture.supplyAsync(() -> x)));
53+
final List<P1<Integer>> p1s = mergeAll(l.map(x -> future(x)));
5354
assertThat(P1.sequence(p1s)._1(), is(l));
5455
}
5556

57+
public static <A> Future<A> future(A a) {
58+
FutureTask<A> ft = new FutureTask<>(() -> a);
59+
new Thread(ft).start();
60+
return ft;
61+
}
62+
5663
@Test
5764
public void testStrategyCallables() throws Exception {
5865
final Strategy<Callable<Integer>> s = strategy(c -> c);

core/src/test/java/fj/data/OptionTest.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void testBind1() {
7575
.foldLeft(accumulator -> list -> accumulator.isEmpty() ?
7676
list.map(List::single) :
7777
accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.<List<Option<Integer>>>nil())
78-
.forEach(list -> {
78+
.foreachDoEffect(list -> {
7979
assertEquals(iif(list.forall(Option::isSome), 0), list.index(0).bind(Option::some));
8080
});
8181

@@ -87,7 +87,7 @@ public void testBind2() {
8787
.foldLeft(accumulator -> list -> accumulator.isEmpty() ?
8888
list.map(List::single) :
8989
accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.<List<Option<Integer>>>nil())
90-
.forEach(list -> {
90+
.foreachDoEffect(list -> {
9191
assertEquals(iif(list.forall(Option::isSome), p(0, 1)), list.index(0).bind(list.index(1), p2()));
9292
});
9393
}
@@ -98,7 +98,7 @@ public void testBind3() {
9898
.foldLeft(accumulator -> list -> accumulator.isEmpty() ?
9999
list.map(List::single) :
100100
accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.<List<Option<Integer>>>nil())
101-
.forEach(list -> {
101+
.foreachDoEffect(list -> {
102102
assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2)), list.index(0).bind(list.index(1), list.index(2), p3()));
103103
});
104104

@@ -110,7 +110,7 @@ public void testBind4() {
110110
.foldLeft(accumulator -> list -> accumulator.isEmpty() ?
111111
list.map(List::single) :
112112
accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.<List<Option<Integer>>>nil())
113-
.forEach(list -> {
113+
.foreachDoEffect(list -> {
114114
assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3)), list.index(0).bind(list.index(1), list.index(2), list.index(3), p4()));
115115
});
116116

@@ -122,7 +122,7 @@ public void testBind5() {
122122
.foldLeft(accumulator -> list -> accumulator.isEmpty() ?
123123
list.map(List::single) :
124124
accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.<List<Option<Integer>>>nil())
125-
.forEach(list -> {
125+
.foreachDoEffect(list -> {
126126
assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3, 4)), list.index(0).bind(list.index(1), list.index(2), list.index(3), list.index(4), p5()));
127127
});
128128
}
@@ -133,7 +133,7 @@ public void testBind6() {
133133
.foldLeft(accumulator -> list -> accumulator.isEmpty() ?
134134
list.map(List::single) :
135135
accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.<List<Option<Integer>>>nil())
136-
.forEach(list -> {
136+
.foreachDoEffect(list -> {
137137
assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3, 4, 5)), list.index(0).bind(list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), p6()));
138138
});
139139
}
@@ -144,7 +144,7 @@ public void testBind7() {
144144
.foldLeft(accumulator -> list -> accumulator.isEmpty() ?
145145
list.map(List::single) :
146146
accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.<List<Option<Integer>>>nil())
147-
.forEach(list -> {
147+
.foreachDoEffect(list -> {
148148
assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3, 4, 5, 6)), list.index(0).bind(list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), list.index(6), p7()));
149149
});
150150
}
@@ -155,7 +155,7 @@ public void testBind8() {
155155
.foldLeft(accumulator -> list -> accumulator.isEmpty() ?
156156
list.map(List::single) :
157157
accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.<List<Option<Integer>>>nil())
158-
.forEach(list -> {
158+
.foreachDoEffect(list -> {
159159
assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3, 4, 5, 6, 7)), list.index(0).bind(list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), list.index(6), list.index(7), P.<Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer>p8()));
160160
});
161161
}
@@ -166,7 +166,7 @@ public void testBindProduct2() {
166166
.foldLeft(accumulator -> list -> accumulator.isEmpty() ?
167167
list.map(List::single) :
168168
accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.<List<Option<Integer>>>nil())
169-
.forEach(list -> {
169+
.foreachDoEffect(list -> {
170170
assertEquals(iif(list.forall(Option::isSome), p(0, 1)), list.index(0).bindProduct(list.index(1)));
171171
});
172172
}
@@ -177,7 +177,7 @@ public void testBindProduct3() {
177177
.foldLeft(accumulator -> list -> accumulator.isEmpty() ?
178178
list.map(List::single) :
179179
accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.<List<Option<Integer>>>nil())
180-
.forEach(list -> {
180+
.foreachDoEffect(list -> {
181181
assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2)), list.index(0).bindProduct(list.index(1), list.index(2)));
182182
});
183183

@@ -189,7 +189,7 @@ public void testBindProduct4() {
189189
.foldLeft(accumulator -> list -> accumulator.isEmpty() ?
190190
list.map(List::single) :
191191
accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.<List<Option<Integer>>>nil())
192-
.forEach(list -> {
192+
.foreachDoEffect(list -> {
193193
assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3)), list.index(0).bindProduct(list.index(1), list.index(2), list.index(3)));
194194
});
195195

@@ -201,7 +201,7 @@ public void testBindProduct5() {
201201
.foldLeft(accumulator -> list -> accumulator.isEmpty() ?
202202
list.map(List::single) :
203203
accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.<List<Option<Integer>>>nil())
204-
.forEach(list -> {
204+
.foreachDoEffect(list -> {
205205
assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3, 4)), list.index(0).bindProduct(list.index(1), list.index(2), list.index(3), list.index(4)));
206206
});
207207
}
@@ -212,7 +212,7 @@ public void testBindProduct6() {
212212
.foldLeft(accumulator -> list -> accumulator.isEmpty() ?
213213
list.map(List::single) :
214214
accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.<List<Option<Integer>>>nil())
215-
.forEach(list -> {
215+
.foreachDoEffect(list -> {
216216
assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3, 4, 5)), list.index(0).bindProduct(list.index(1), list.index(2), list.index(3), list.index(4), list.index(5)));
217217
});
218218
}
@@ -223,7 +223,7 @@ public void testBindProduct7() {
223223
.foldLeft(accumulator -> list -> accumulator.isEmpty() ?
224224
list.map(List::single) :
225225
accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.<List<Option<Integer>>>nil())
226-
.forEach(list -> {
226+
.foreachDoEffect(list -> {
227227
assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3, 4, 5, 6)), list.index(0).bindProduct(list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), list.index(6)));
228228
});
229229
}
@@ -234,7 +234,7 @@ public void testBindProduct8() {
234234
.foldLeft(accumulator -> list -> accumulator.isEmpty() ?
235235
list.map(List::single) :
236236
accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.<List<Option<Integer>>>nil())
237-
.forEach(list -> {
237+
.foreachDoEffect(list -> {
238238
assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3, 4, 5, 6, 7)), list.index(0).bindProduct(list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), list.index(6), list.index(7)));
239239
});
240240
}

0 commit comments

Comments
 (0)