WEBVTT

00:00.320 --> 00:00.890
Hi everyone.

00:00.890 --> 00:02.180
Welcome back to this tutorial.

00:02.180 --> 00:07.260
In this tutorial we will code and explore the by function functional interface.

00:07.280 --> 00:12.470
The first step is I'm going to search for that by function function interface and then see what is that

00:12.470 --> 00:13.280
all about.

00:16.160 --> 00:21.200
So by function, functional interface is similar to the function interface, but the only difference

00:21.200 --> 00:24.950
is the by function accepts two inputs and then produces one output.

00:25.100 --> 00:28.760
I'm going to open the function functional interface two and then compare these two.

00:31.090 --> 00:36.100
So if we take a look at the function, it has a play method as like the by function method, but it

00:36.100 --> 00:39.010
accepts only one input and one output.

00:39.630 --> 00:45.870
And it has a compost method and another method and it has a static identity method.

00:46.110 --> 00:49.830
But the by function method doesn't have all those methods.

00:49.830 --> 00:51.840
It just has the and then method.

00:52.680 --> 00:54.570
Now let's go ahead and code this.

00:55.550 --> 00:58.700
Scenario using the by function functional interface.

00:59.180 --> 01:01.250
I'm going to create a class called.

01:02.090 --> 01:03.050
By function.

01:04.580 --> 01:05.180
Example.

01:06.900 --> 01:11.790
And then I'm going to make this class executable by adding the public static void main method.

01:11.880 --> 01:17.160
The use case that we are going to code is that my function is going to accept two inputs, right?

01:17.190 --> 01:19.020
First one is going to be the list of students.

01:19.020 --> 01:23.160
The second one we are going to pass a predicate as an input.

01:23.160 --> 01:29.100
So until now, we have never passed a functional interface implementation as an input.

01:29.190 --> 01:35.190
In this example, we are going to explore that and the output is going to be a map of students and their

01:35.190 --> 01:36.930
respective GPAs.

01:37.350 --> 01:42.390
Let's create the instance of by function function, interface by function.

01:42.390 --> 01:44.280
So it is going to take three.

01:45.440 --> 01:50.030
Parameters passed to are going to be the input and third one is going to be the output.

01:50.240 --> 01:52.940
The first one is going to be the list of students.

01:54.500 --> 01:56.240
Riggo Coldset.

01:56.240 --> 01:58.220
And the next one is going to be.

01:59.060 --> 02:01.190
Predicate of student.

02:03.760 --> 02:09.970
So this is the functional interface which we are passing as an input to that by function functional

02:09.970 --> 02:10.510
interface.

02:11.640 --> 02:15.900
Predicate of student hours typo here.

02:16.620 --> 02:17.790
Let's import predicate.

02:18.850 --> 02:19.960
The third one is the output.

02:19.990 --> 02:20.650
What is the input?

02:20.680 --> 02:21.560
We are output.

02:21.580 --> 02:23.710
The output is going to be map of.

02:24.820 --> 02:31.870
Ring and double basically map of the names, which is of type string and their respective GPUs.

02:31.900 --> 02:32.920
GPUs are in.

02:36.400 --> 02:38.890
And I'm going to give a name by function.

02:39.640 --> 02:41.560
So this is going to accept.

02:43.090 --> 02:46.000
The shouldn't list, which is equivalent to students.

02:47.050 --> 02:51.130
And then is going to perform some operation.

02:51.490 --> 02:54.310
The first step is we are going to initialize.

02:55.950 --> 02:57.090
String double.

02:57.090 --> 02:59.730
We are going to create a HashMap.

03:02.960 --> 03:08.660
Student grade map equal to new hash map.

03:11.200 --> 03:11.500
It.

03:11.860 --> 03:12.570
What is the next step?

03:12.580 --> 03:16.540
The next step is we are going to iterate the student list.

03:17.970 --> 03:18.600
Reach.

03:21.760 --> 03:23.680
And we are going to use.

03:24.870 --> 03:25.710
This predicate.

03:26.620 --> 03:28.990
Right if shouldn't predicate.

03:30.310 --> 03:32.380
Dot test student.

03:34.010 --> 03:39.020
Then add those student in the student grade map dot put.

03:39.780 --> 03:44.550
Didn't dot get name comma didn't dot get.

03:46.870 --> 03:49.180
And then we have to return this hash map.

03:49.540 --> 03:53.020
The next thing, return the student grade map.

03:54.640 --> 03:56.110
Not a semicolon here.

03:56.590 --> 03:57.100
There you go.

03:57.100 --> 04:00.790
We have the by function functional interface implementation ready.

04:00.820 --> 04:03.850
The next step is we are going to pass some input to it.

04:04.240 --> 04:08.050
So let's create the System.out.println.

04:09.630 --> 04:10.080
In here.

04:10.080 --> 04:14.400
What we are going to do, we are going to do by function dot apply.

04:14.430 --> 04:15.180
We take a look at it.

04:15.180 --> 04:17.050
It takes two input parameters.

04:17.080 --> 04:19.440
So using the student database class.

04:21.710 --> 04:26.670
Database, you're going to get all the list of students and then we have to pass a predicate.

04:26.690 --> 04:28.310
Let's go and check this predicate.

04:28.310 --> 04:29.270
Student example.

04:29.600 --> 04:35.180
I'm going to use this predicate in order to filter the.

04:37.540 --> 04:38.340
Students.

04:38.350 --> 04:41.590
So I'm going to use predicate example.

04:44.600 --> 04:45.270
Pterygoids.

04:45.470 --> 04:48.200
F stands for Functional interface.

04:48.230 --> 04:49.340
We're going to use P1.

04:49.580 --> 04:50.060
Basically.

04:50.060 --> 04:51.470
What is that it is going to do?

04:51.470 --> 04:55.080
It is going to filter the students based on their grade level.

04:55.100 --> 05:02.060
So it is going to produce the output with all the students who are the grade level greater than or equal

05:02.060 --> 05:02.690
to three.

05:03.900 --> 05:05.310
Then I'm going to run this example.

05:08.840 --> 05:09.350
There you go.

05:09.380 --> 05:14.450
It gave all the students whose grade level is greater than or equal to three.

05:14.450 --> 05:20.450
Let's say you change your mind and then you want to use this another functional interface predicate

05:20.540 --> 05:26.510
implementation, which has this filter which is equivalent to the GPA greater than or equal to 3.9.

05:26.960 --> 05:28.040
I'm going to run this.

05:29.200 --> 05:30.980
Is going to produce a result accordingly.

05:31.160 --> 05:38.420
Now it is only three results in the output because only three results from this election matches the

05:38.420 --> 05:39.110
filter.

05:39.110 --> 05:45.620
Basically, who are having the grade, which is the GPA greater than or equal to 3.9.

05:47.790 --> 05:48.120
With this.

05:48.120 --> 05:49.810
We came to the end of this tutorial.

05:49.830 --> 05:50.910
Thank you for watching.
