Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

list-ops: add to track #207

Merged
merged 13 commits into from
Feb 21, 2017
6 changes: 6 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"twelve-days",
"sublist",
"rectangles",
"matrix",
"list-ops"
],
"exercises": [
Expand Down Expand Up @@ -325,6 +326,11 @@
"difficulty": 1,
"topics": []
},
{
"slug": "matrix",
"difficulty": 1,
"topics": []
},
{
"slug": "list-ops",
"difficulty": 1,
Expand Down
15 changes: 15 additions & 0 deletions exercises/list-ops/src/example/java/ListOps.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.BinaryOperator;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -48,4 +51,16 @@ public static <T> List<T> concat(final List<T>... lists) {
.collect(Collectors.toList());
}

public static <R,T> R collect(final List<T> list,
Supplier<R> supplier,
BiConsumer<R, ? super T> accumulator,
BiConsumer<R, R> combiner) {
return list.stream().collect(supplier, accumulator, combiner);
}

public static <R, T, A> R collect(final List<T> list,
Collector<T, A, R> collector) {
return list.stream().collect(collector);
}

}
Loading