Parcourir la source

done pt 7, onto pt 8

Katrice Williams-Dredden il y a 6 ans
Parent
révision
8aedfcd1e9
1 fichiers modifiés avec 7 ajouts et 1 suppressions
  1. 7
    1
      src/main/java/MapFunc/MapFunc.java

+ 7
- 1
src/main/java/MapFunc/MapFunc.java Voir le fichier

12
     //okay katrice, so public method is because this test does not create a instance of MapFunc
12
     //okay katrice, so public method is because this test does not create a instance of MapFunc
13
     //The <T, R> when its static you have to define the generic so you can pass it into a static
13
     //The <T, R> when its static you have to define the generic so you can pass it into a static
14
     //We are returning an Arraylist of the results and they take in an ArrayList of type T
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
 }