-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBiFunctionExample.java
29 lines (23 loc) · 957 Bytes
/
BiFunctionExample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.learn.functionalInterfaces;
import com.learn.data.Student;
import com.learn.data.StudentDataBase;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Predicate;
public class BiFunctionExample {
static BiFunction<List<Student>, Predicate<Student>, Map<String, Double>> biFunction =
((students, studentPredicate) -> {
Map<String, Double> studentGradeMap = new HashMap<>();
students.forEach(student -> {
if (studentPredicate.test(student)) {
studentGradeMap.put(student.getName(), student.getGpa());
}
});
return studentGradeMap;
});
public static void main(String[] args) {
System.out.println(biFunction.apply(StudentDataBase.getAllStudents(), PredicateStudentExample.predicate1));
}
}