Skip to content

Commit 4795c30

Browse files
authored
Rename FunctionAccum with BiFunction.
1 parent a374129 commit 4795c30

File tree

14 files changed

+51
-51
lines changed

14 files changed

+51
-51
lines changed

math-plugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<plugin>
5050
<groupId>org.apache.maven.plugins</groupId>
5151
<artifactId>maven-compiler-plugin</artifactId>
52-
<version>3.5.1</version>
52+
<version>3.7.0</version>
5353
<configuration>
5454
<source>1.6</source>
5555
<target>1.6</target>

math-plugin/src/main/java/com/github/underscore/math/$.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
*/
2424
package com.github.underscore.math;
2525

26+
import com.github.underscore.BiFunction;
2627
import com.github.underscore.Consumer;
2728
import com.github.underscore.Function;
28-
import com.github.underscore.FunctionAccum;
2929
import com.github.underscore.Predicate;
3030
import com.github.underscore.PredicateIndexed;
3131
import com.github.underscore.Tuple;
@@ -135,11 +135,11 @@ public Chain<T> filterFalse(final Predicate<T> pred) {
135135
return new Chain<T>($.filterFalse(value(), pred));
136136
}
137137

138-
public <F> Chain<F> reduce(final FunctionAccum<F, T> func, final F zeroElem) {
138+
public <F> Chain<F> reduce(final BiFunction<F, T, F> func, final F zeroElem) {
139139
return new Chain<F>($.reduce(value(), func, zeroElem));
140140
}
141141

142-
public <F> Chain<F> reduceRight(final FunctionAccum<F, T> func, final F zeroElem) {
142+
public <F> Chain<F> reduceRight(final BiFunction<F, T, F> func, final F zeroElem) {
143143
return new Chain<F>($.reduceRight(value(), func, zeroElem));
144144
}
145145

math-plugin/src/test/java/com/github/underscore/math/MathTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
*/
2424
package com.github.underscore.math;
2525

26+
import com.github.underscore.BiFunction;
2627
import com.github.underscore.Consumer;
2728
import com.github.underscore.Function;
28-
import com.github.underscore.FunctionAccum;
2929
import com.github.underscore.Predicate;
3030
import com.github.underscore.PredicateIndexed;
3131
import com.github.underscore.Tuple;
@@ -304,9 +304,9 @@ public void chain() {
304304
public boolean test(int index, String str) { return true; } });
305305
$.chain(new String[] {""}).filterFalse(new Predicate<String>() {
306306
public boolean test(String str) { return true; } });
307-
$.chain(new String[] {""}).reduce(new FunctionAccum<String, String>() {
307+
$.chain(new String[] {""}).reduce(new BiFunction<String, String, String>() {
308308
public String apply(String accum, String str) { return null; } }, "");
309-
$.chain(new String[] {""}).reduceRight(new FunctionAccum<String, String>() {
309+
$.chain(new String[] {""}).reduceRight(new BiFunction<String, String, String>() {
310310
public String apply(String accum, String str) { return null; } }, "");
311311
$.chain(new String[] {""}).find(new Predicate<String>() {
312312
public boolean test(String str) { return true; } });

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@
140140
<option>-keepattributes Signature,InnerClasses</option>
141141
<option>-keep public class com.github.underscore.$ { *; }</option>
142142
<option>-keep public class com.github.underscore.*$Chain { *; }</option>
143+
<option>-keep public class com.github.underscore.BiFunction { *; }</option>
143144
<option>-keep public class com.github.underscore.Consumer { *; }</option>
144145
<option>-keep public class com.github.underscore.Function { *; }</option>
145146
<option>-keep public class com.github.underscore.Function3 { *; }</option>
146-
<option>-keep public class com.github.underscore.FunctionAccum { *; }</option>
147147
<option>-keep public class com.github.underscore.MemoizeFunction { *; }</option>
148148
<option>-keep public class com.github.underscore.Optional { *; }</option>
149149
<option>-keep public class com.github.underscore.Predicate { *; }</option>

src/main/java/com/github/underscore/$.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -287,55 +287,55 @@ public static <T, E> Set<T> collect(final Set<E> set, final Function<? super E,
287287
return map(set, func);
288288
}
289289

290-
public static <T, E> E reduce(final Iterable<T> iterable, final FunctionAccum<E, T> func, final E zeroElem) {
290+
public static <T, E> E reduce(final Iterable<T> iterable, final BiFunction<E, T, E> func, final E zeroElem) {
291291
E accum = zeroElem;
292292
for (T element : iterable) {
293293
accum = func.apply(accum, element);
294294
}
295295
return accum;
296296
}
297297

298-
public static <E> E reduce(final int[] array, final FunctionAccum<E, ? super Integer> func, final E zeroElem) {
298+
public static <E> E reduce(final int[] array, final BiFunction<E, ? super Integer, E> func, final E zeroElem) {
299299
E accum = zeroElem;
300300
for (int element : array) {
301301
accum = func.apply(accum, element);
302302
}
303303
return accum;
304304
}
305305

306-
public static <T, E> E reduce(final T[] array, final FunctionAccum<E, T> func, final E zeroElem) {
306+
public static <T, E> E reduce(final T[] array, final BiFunction<E, T, E> func, final E zeroElem) {
307307
E accum = zeroElem;
308308
for (T element : array) {
309309
accum = func.apply(accum, element);
310310
}
311311
return accum;
312312
}
313313

314-
public static <T, E> E foldl(final Iterable<T> iterable, final FunctionAccum<E, T> func, final E zeroElem) {
314+
public static <T, E> E foldl(final Iterable<T> iterable, final BiFunction<E, T, E> func, final E zeroElem) {
315315
return reduce(iterable, func, zeroElem);
316316
}
317317

318-
public static <T, E> E inject(final Iterable<T> iterable, final FunctionAccum<E, T> func, final E zeroElem) {
318+
public static <T, E> E inject(final Iterable<T> iterable, final BiFunction<E, T, E> func, final E zeroElem) {
319319
return reduce(iterable, func, zeroElem);
320320
}
321321

322-
public static <T, E> E reduceRight(final Iterable<T> iterable, final FunctionAccum<E, T> func, final E zeroElem) {
322+
public static <T, E> E reduceRight(final Iterable<T> iterable, final BiFunction<E, T, E> func, final E zeroElem) {
323323
return reduce(reverse(iterable), func, zeroElem);
324324
}
325325

326-
public static <E> E reduceRight(final int[] array, final FunctionAccum<E, ? super Integer> func, final E zeroElem) {
326+
public static <E> E reduceRight(final int[] array, final BiFunction<E, ? super Integer, E> func, final E zeroElem) {
327327
E accum = zeroElem;
328328
for (Integer element : reverse(array)) {
329329
accum = func.apply(accum, element);
330330
}
331331
return accum;
332332
}
333333

334-
public static <T, E> E reduceRight(final T[] array, final FunctionAccum<E, T> func, final E zeroElem) {
334+
public static <T, E> E reduceRight(final T[] array, final BiFunction<E, T, E> func, final E zeroElem) {
335335
return reduce(reverse(array), func, zeroElem);
336336
}
337337

338-
public static <T, E> E foldr(final Iterable<T> iterable, final FunctionAccum<E, T> func, final E zeroElem) {
338+
public static <T, E> E foldr(final Iterable<T> iterable, final BiFunction<E, T, E> func, final E zeroElem) {
339339
return reduceRight(iterable, func, zeroElem);
340340
}
341341

@@ -2127,11 +2127,11 @@ public Chain<T> filterFalse(final Predicate<T> pred) {
21272127
return new Chain<T>($.reject(list, pred));
21282128
}
21292129

2130-
public <F> Chain<F> reduce(final FunctionAccum<F, T> func, final F zeroElem) {
2130+
public <F> Chain<F> reduce(final BiFunction<F, T, F> func, final F zeroElem) {
21312131
return new Chain<F>($.reduce(list, func, zeroElem));
21322132
}
21332133

2134-
public <F> Chain<F> reduceRight(final FunctionAccum<F, T> func, final F zeroElem) {
2134+
public <F> Chain<F> reduceRight(final BiFunction<F, T, F> func, final F zeroElem) {
21352135
return new Chain<F>($.reduceRight(list, func, zeroElem));
21362136
}
21372137

src/main/java/com/github/underscore/FunctionAccum.java renamed to src/main/java/com/github/underscore/BiFunction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.github.underscore;
22

3-
public interface FunctionAccum<A, F> {
4-
A apply(A accum, F arg);
3+
public interface BiFunction<F1, F2, T> {
4+
T apply(F1 arg1, F2 arg2);
55

66
@Override
77
boolean equals(Object object);

src/main/java/com/github/underscore/lodash/$.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
*/
2424
package com.github.underscore.lodash;
2525

26+
import com.github.underscore.BiFunction;
2627
import com.github.underscore.Consumer;
2728
import com.github.underscore.Function;
2829
import com.github.underscore.Function3;
29-
import com.github.underscore.FunctionAccum;
3030
import com.github.underscore.Predicate;
3131
import com.github.underscore.PredicateIndexed;
3232
import com.github.underscore.Tuple;
@@ -181,11 +181,11 @@ public Chain<T> filterFalse(final Predicate<T> pred) {
181181
return new Chain<T>($.filterFalse(value(), pred));
182182
}
183183

184-
public <F> Chain<F> reduce(final FunctionAccum<F, T> func, final F zeroElem) {
184+
public <F> Chain<F> reduce(final BiFunction<F, T, F> func, final F zeroElem) {
185185
return new Chain<F>($.reduce(value(), func, zeroElem));
186186
}
187187

188-
public <F> Chain<F> reduceRight(final FunctionAccum<F, T> func, final F zeroElem) {
188+
public <F> Chain<F> reduceRight(final BiFunction<F, T, F> func, final F zeroElem) {
189189
return new Chain<F>($.reduceRight(value(), func, zeroElem));
190190
}
191191

src/test/java/com/github/underscore/ChainingTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public List<String> apply(Map<String, Object> item) {
193193
})
194194
.flatten()
195195
.reduce(
196-
new FunctionAccum<Map<String, Integer>, String>() {
196+
new BiFunction<Map<String, Integer>, String, Map<String, Integer>>() {
197197
public Map<String, Integer> apply(Map<String, Integer> accum, String item) {
198198
if (accum.get(item) == null) {
199199
accum.put(item, 1);
@@ -251,7 +251,7 @@ public List<String> apply(Map<String, Object> item) {
251251
})
252252
.flatten()
253253
.reduceRight(
254-
new FunctionAccum<Map<String, Integer>, String>() {
254+
new BiFunction<Map<String, Integer>, String, Map<String, Integer>>() {
255255
public Map<String, Integer> apply(Map<String, Integer> accum, String item) {
256256
if (accum.get(item) == null) {
257257
accum.put(item, 1);
@@ -365,7 +365,7 @@ public void chain5() {
365365
@SuppressWarnings("unchecked")
366366
public void chain6() {
367367
final List<Comparable> result = $.chain($.chain($.class.getDeclaredMethods())
368-
.reduce(new FunctionAccum<List<String>, Method>() {
368+
.reduce(new BiFunction<List<String>, Method, List<String>>() {
369369
public List<String> apply(final List<String> accum, final Method method) {
370370
accum.add(method.getName());
371371
return accum;
@@ -406,7 +406,7 @@ public Integer apply(String w) {
406406
return w.length();
407407
}
408408
})
409-
.reduce(new FunctionAccum<Integer, Integer>() {
409+
.reduce(new BiFunction<Integer, Integer, Integer>() {
410410
public Integer apply(Integer accum, Integer length) {
411411
return accum + length;
412412
}
@@ -445,7 +445,7 @@ public Character apply(final String name) {
445445
@SuppressWarnings("unchecked")
446446
public void chain9() {
447447
final List<Comparable> result = $.chain($.chain($.class.getDeclaredMethods())
448-
.reduce(new FunctionAccum<List<String>, Method>() {
448+
.reduce(new BiFunction<List<String>, Method, List<String>>() {
449449
public List<String> apply(final List<String> accum, final Method method) {
450450
accum.add(method.getName());
451451
return accum;

src/test/java/com/github/underscore/CollectionsTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public Integer apply(Integer item) {
249249
public void reduce() {
250250
final Integer result =
251251
$.reduce(asList(1, 2, 3),
252-
new FunctionAccum<Integer, Integer>() {
252+
new BiFunction<Integer, Integer, Integer>() {
253253
public Integer apply(Integer item1, Integer item2) {
254254
return item1 + item2;
255255
}
@@ -266,7 +266,7 @@ public Integer apply(Integer item1, Integer item2) {
266266
public void reduceIntArray() {
267267
final Integer result =
268268
$.reduce(new int[]{1, 2, 3},
269-
new FunctionAccum<Integer, Integer>() {
269+
new BiFunction<Integer, Integer, Integer>() {
270270
public Integer apply(Integer item1, Integer item2) {
271271
return item1 + item2;
272272
}
@@ -283,7 +283,7 @@ public Integer apply(Integer item1, Integer item2) {
283283
public void reduceArray() {
284284
final Integer result =
285285
$.reduce(new Integer[]{1, 2, 3},
286-
new FunctionAccum<Integer, Integer>() {
286+
new BiFunction<Integer, Integer, Integer>() {
287287
public Integer apply(Integer item1, Integer item2) {
288288
return item1 + item2;
289289
}
@@ -302,7 +302,7 @@ public Integer apply(Integer item1, Integer item2) {
302302
public void inject() {
303303
final List<Integer> result =
304304
$.inject(asList(asList(0, 1), asList(2, 3), asList(4, 5)),
305-
new FunctionAccum<List<Integer>, List<Integer>>() {
305+
new BiFunction<List<Integer>, List<Integer>, List<Integer>>() {
306306
public List<Integer> apply(List<Integer> item1, List<Integer> item2) {
307307
List<Integer> list = new ArrayList<Integer>(item1);
308308
list.addAll(item2);
@@ -324,7 +324,7 @@ public List<Integer> apply(List<Integer> item1, List<Integer> item2) {
324324
public void foldl() {
325325
final List<Integer> result =
326326
$.foldl(asList(asList(0, 1), asList(2, 3), asList(4, 5)),
327-
new FunctionAccum<List<Integer>, List<Integer>>() {
327+
new BiFunction<List<Integer>, List<Integer>, List<Integer>>() {
328328
public List<Integer> apply(List<Integer> item1, List<Integer> item2) {
329329
List<Integer> list = new ArrayList<Integer>(item1);
330330
list.addAll(item2);
@@ -346,7 +346,7 @@ public List<Integer> apply(List<Integer> item1, List<Integer> item2) {
346346
public void reduceRight() {
347347
final List<Integer> result =
348348
$.reduceRight(asList(asList(0, 1), asList(2, 3), asList(4, 5)),
349-
new FunctionAccum<List<Integer>, List<Integer>>() {
349+
new BiFunction<List<Integer>, List<Integer>, List<Integer>>() {
350350
public List<Integer> apply(List<Integer> item1, List<Integer> item2) {
351351
List<Integer> list = new ArrayList<Integer>(item1);
352352
list.addAll(item2);
@@ -366,7 +366,7 @@ public List<Integer> apply(List<Integer> item1, List<Integer> item2) {
366366
public void reduceRightIntArray() {
367367
final Integer result =
368368
$.reduceRight(new int[]{1, 2, 3},
369-
new FunctionAccum<Integer, Integer>() {
369+
new BiFunction<Integer, Integer, Integer>() {
370370
public Integer apply(Integer item1, Integer item2) {
371371
return item1 + item2;
372372
}
@@ -383,7 +383,7 @@ public Integer apply(Integer item1, Integer item2) {
383383
public void reduceRightArray() {
384384
final Integer result =
385385
$.reduceRight(new Integer[]{1, 2, 3},
386-
new FunctionAccum<Integer, Integer>() {
386+
new BiFunction<Integer, Integer, Integer>() {
387387
public Integer apply(Integer item1, Integer item2) {
388388
return item1 + item2;
389389
}
@@ -402,7 +402,7 @@ public Integer apply(Integer item1, Integer item2) {
402402
public void foldr() {
403403
final List<Integer> result =
404404
$.foldr(asList(asList(0, 1), asList(2, 3), asList(4, 5)),
405-
new FunctionAccum<List<Integer>, List<Integer>>() {
405+
new BiFunction<List<Integer>, List<Integer>, List<Integer>>() {
406406
public List<Integer> apply(List<Integer> item1, List<Integer> item2) {
407407
List<Integer> list = new ArrayList<Integer>(item1);
408408
list.addAll(item2);

src/test/java/com/github/underscore/lodash/LodashTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
*/
2424
package com.github.underscore.lodash;
2525

26+
import com.github.underscore.BiFunction;
2627
import com.github.underscore.Consumer;
2728
import com.github.underscore.Function;
28-
import com.github.underscore.FunctionAccum;
2929
import com.github.underscore.Predicate;
3030
import com.github.underscore.PredicateIndexed;
3131
import com.github.underscore.Tuple;
@@ -613,9 +613,9 @@ public void chain() {
613613
public boolean test(int index, String str) { return true; } });
614614
$.chain(new String[] {""}).filterFalse(new Predicate<String>() {
615615
public boolean test(String str) { return true; } });
616-
$.chain(new String[] {""}).reduce(new FunctionAccum<String, String>() {
616+
$.chain(new String[] {""}).reduce(new BiFunction<String, String, String>() {
617617
public String apply(String accum, String str) { return null; } }, "");
618-
$.chain(new String[] {""}).reduceRight(new FunctionAccum<String, String>() {
618+
$.chain(new String[] {""}).reduceRight(new BiFunction<String, String, String>() {
619619
public String apply(String accum, String str) { return null; } }, "");
620620
$.chain(new String[] {""}).find(new Predicate<String>() {
621621
public boolean test(String str) { return true; } });

0 commit comments

Comments
 (0)