WEBVTT

00:00.520 --> 00:01.000
Hi everyone.

00:01.000 --> 00:02.200
Welcome back to this tutorial.

00:02.200 --> 00:08.260
In this tutorial, we'll explore the function interface using that student collection that we have been

00:08.260 --> 00:10.510
using throughout the tutorial.

00:10.510 --> 00:20.560
Now the use cases, we are going to create a map of students and their respective grades meaning and

00:20.560 --> 00:21.940
their respective GPA.

00:23.260 --> 00:23.920
For that purpose.

00:23.920 --> 00:31.450
What I'm going to do, I'm going to create a new class called function student example.

00:32.770 --> 00:34.630
Then I'm going to make this class executable.

00:35.410 --> 00:36.340
SVM.

00:36.790 --> 00:37.630
There you go.

00:37.750 --> 00:39.430
Class is executable now.

00:40.210 --> 00:44.200
The first step is we are going to create the function interface.

00:44.320 --> 00:45.130
Static.

00:46.000 --> 00:47.170
Function interface.

00:48.300 --> 00:50.580
So the input is going to be.

00:52.380 --> 00:59.230
A list of students and the output is going to be a hash map with the student and their GPA.

01:01.610 --> 01:02.900
The list of.

01:03.730 --> 01:05.200
Student is the input.

01:07.080 --> 01:14.520
Followed by that I'm using the option and return to auto import these classes in Mac.

01:15.410 --> 01:18.020
You take a look at the windows, it's alt enter.

01:20.970 --> 01:24.360
And the next thing is it's going to be a map of string.

01:26.220 --> 01:27.090
And double.

01:27.450 --> 01:34.980
The double is a type which is being used to store the student GPAs.

01:35.010 --> 01:36.120
We take a look at it.

01:36.420 --> 01:37.470
The double.

01:39.110 --> 01:40.730
That's what we have been using here.

01:42.180 --> 01:43.050
And then.

01:45.390 --> 01:48.060
For that, let's import the function.

01:48.300 --> 01:49.050
Here you go.

01:49.230 --> 01:49.830
All set?

01:51.020 --> 01:53.060
You're going to name this one as.

01:54.420 --> 01:55.500
Student function.

01:56.770 --> 02:00.100
Now, we all know the input is going to be students, right?

02:00.730 --> 02:01.300
There you go.

02:01.600 --> 02:08.260
And then we are going to open the curly braces because we are going to do a lot of logic in order to

02:08.260 --> 02:09.640
get to that result.

02:09.850 --> 02:13.960
So the lambda body is going to be more than a single line statement.

02:13.960 --> 02:17.710
That's the reason why we have the curly braces open here.

02:18.370 --> 02:19.300
In here.

02:19.300 --> 02:23.770
The first step is we are going to define a map that's going to be string.

02:27.580 --> 02:30.880
And then it is going to be named as student.

02:32.140 --> 02:35.140
Read map equal to new.

02:38.910 --> 02:39.180
Okay.

02:39.330 --> 02:41.100
Now we are going to.

02:41.870 --> 02:47.480
In that shouldn't and using the for each method what we are going to do.

02:48.740 --> 02:51.980
We are going to iterate each and every student.

02:54.200 --> 02:57.590
And then again, open the lambda body.

02:58.190 --> 03:03.350
You're going to populate the student grade map using the put method.

03:03.860 --> 03:07.190
First is going to be to the name.

03:08.220 --> 03:11.640
Followed by that it is going to have student dot get GPA.

03:12.760 --> 03:13.300
There you go.

03:13.420 --> 03:18.490
The map is going to be populated with the student and their appropriate grades.

03:18.910 --> 03:20.710
Now, I'm going to close this.

03:21.430 --> 03:22.800
I have some issues here.

03:22.800 --> 03:23.640
What is that?

03:26.230 --> 03:28.990
This particular map have to return something, right?

03:28.990 --> 03:31.690
This is going to return the student grade map.

03:33.280 --> 03:34.530
Then student grade map.

03:35.560 --> 03:44.260
So now we have implemented the whole functionality and then assign that functionality to this.

03:45.150 --> 03:48.600
Object reference basically to this object.

03:51.510 --> 04:00.720
Now what I'm going to do, I'm going to call the student function dot apply and use a student database

04:00.720 --> 04:04.770
class and get all the students and.

04:05.760 --> 04:09.930
The result is going to be the map of students and their appropriate grades.

04:11.720 --> 04:12.110
There you go.

04:12.350 --> 04:16.400
It printed the value with the students and their appropriate grades.

04:16.430 --> 04:18.920
Now you are changing your mindset.

04:18.920 --> 04:23.410
And then there is a new request came from the business.

04:23.420 --> 04:28.790
Okay, now we want to filter all the students who are greater than.

04:30.130 --> 04:34.000
Grade three level, meaning we go and take a look at the student.

04:34.030 --> 04:35.560
It has a grade level.

04:35.950 --> 04:41.370
They want the students who are the grade of three and four.

04:41.380 --> 04:43.060
So in that case.

04:44.800 --> 04:46.960
You can just change your functionality.

04:47.050 --> 04:52.210
If you take a look at the predicate student example, we have this right and it is defined in static

04:52.210 --> 04:53.080
context.

04:53.080 --> 04:54.610
So I'm going to make use of that.

04:55.070 --> 04:59.590
I'm going to go back to the function student example in here, what I'm going to do.

05:00.900 --> 05:04.050
And apply this logic predicate example Dot.

05:06.450 --> 05:09.300
Believe it is P1 to go to P1.

05:09.540 --> 05:13.260
P1 is the one which has a grade level greater than or equal to three.

05:13.510 --> 05:15.420
Dot test student.

05:17.370 --> 05:24.600
Now, if you take a look at it, we are filtering the student students who are in the grade of three

05:24.600 --> 05:25.100
and four.

05:25.110 --> 05:29.220
Basically, Adam and Emily, they're not going to be printed in the result.

05:31.070 --> 05:31.670
There you go.

05:32.030 --> 05:32.750
Emily is printed.

05:32.750 --> 05:35.840
I believe Emily is part of the third grade only.

05:35.840 --> 05:36.330
Yep.

05:36.350 --> 05:39.020
The result is printed as expected.

05:39.440 --> 05:44.040
So this is the advantage of using lambdas.

05:44.060 --> 05:45.680
So you can plug in.

05:46.840 --> 05:49.330
New features very easily.

05:49.450 --> 05:52.840
And then and it is more readable.

05:53.350 --> 05:58.210
So that's one of the advantage of using Lambda, which have been highlighting from the beginning.

05:59.580 --> 05:59.940
With this.

05:59.940 --> 06:01.740
We came to the end of this tutorial.

06:01.860 --> 06:02.910
Thank you for watching.
