lots of exercises in java... from https://github.com/exercism/java

ListOps.java 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import java.util.List;
  2. import java.util.function.BiFunction;
  3. import java.util.function.Function;
  4. import java.util.function.Predicate;
  5. class ListOps {
  6. static <T> List<T> append(List<T> list1, List<T> list2) {
  7. throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
  8. }
  9. static <T> List<T> concat(List<List<T>> listOfLists) {
  10. throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
  11. }
  12. static <T> List<T> filter(List<T> list, Predicate<T> predicate) {
  13. throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
  14. }
  15. static <T> int size(List<T> list) {
  16. throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
  17. }
  18. static <T, U> List<U> map(List<T> list, Function<T, U> transform) {
  19. throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
  20. }
  21. static <T> List<T> reverse(List<T> list) {
  22. throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
  23. }
  24. static <T, U> U foldLeft(List<T> list, U initial, BiFunction<U, T, U> f) {
  25. throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
  26. }
  27. static <T, U> U foldRight(List<T> list, U initial, BiFunction<T, U, U> f) {
  28. throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
  29. }
  30. private ListOps() {
  31. // No instances.
  32. }
  33. }