Explorar el Código

done pt 7, onto pt 8

Katrice Williams-Dredden hace 6 años
padre
commit
8aedfcd1e9
Se han modificado 1 ficheros con 7 adiciones y 1 borrados
  1. 7
    1
      src/main/java/MapFunc/MapFunc.java

+ 7
- 1
src/main/java/MapFunc/MapFunc.java Ver fichero

@@ -12,7 +12,13 @@ public class MapFunc {
12 12
     //okay katrice, so public method is because this test does not create a instance of MapFunc
13 13
     //The <T, R> when its static you have to define the generic so you can pass it into a static
14 14
     //We are returning an Arraylist of the results and they take in an ArrayList of type T
15
-    public static <T,R> ArrayList<R> map(ArrayList<T>, Function<T,R>){
15
+    public static <T,R> ArrayList<R> map(ArrayList<T> lists, Function<T,R> function){
16
+        ArrayList<R> result = new ArrayList<>();
17
+        for(T item: lists){
18
+            R entry = function.apply(item);
19
+            result.add(entry);
16 20
 
21
+        }
22
+        return result;
17 23
     }
18 24
 }