1
00:00:01,100 --> 00:00:07,190
All right, so in the next couple of videos, we are going to use a bunch of lambda expressions, and

2
00:00:07,190 --> 00:00:11,870
in general, it's a good idea for you to understand Lumba expressions in more depth because we have

3
00:00:11,870 --> 00:00:14,490
covered them, but really just a tiny bit.

4
00:00:14,690 --> 00:00:19,070
And now we're going to see the different aspects of lambda expressions and how they are used and the

5
00:00:19,070 --> 00:00:20,580
advantages and so forth.

6
00:00:20,600 --> 00:00:25,190
So I'm going to go over that in this presentation, but then we're going to use it extensively in the

7
00:00:25,550 --> 00:00:30,470
room database demo as well as in the rest of the course, basically.

8
00:00:30,950 --> 00:00:33,950
So let's look at CoQ10 lambdas.

9
00:00:34,520 --> 00:00:41,270
So lenders are popular in different programming language, and they are well known for, for example,

10
00:00:41,300 --> 00:00:44,870
being simple and concise way to create functions.

11
00:00:45,890 --> 00:00:53,240
Then they are also known as functions with no name because you can just add implementations within its

12
00:00:53,240 --> 00:00:58,580
block, and then they are also used to parse functions as parameters to other functions.

13
00:00:59,180 --> 00:01:00,110
So let's look at this.

14
00:01:00,740 --> 00:01:04,550
So there are various ways to create a lambda function, depending on the requirements.

15
00:01:04,879 --> 00:01:07,220
One is as a parameter, for example.

16
00:01:07,460 --> 00:01:14,000
So you see, we have first the variable name, then a column with the parentheses for the parameter

17
00:01:14,210 --> 00:01:17,240
and then an arrow with a return type.

18
00:01:17,930 --> 00:01:27,440
And here's an example with some as the variable in the integer parameter named result and a unit return

19
00:01:27,440 --> 00:01:30,530
type, which means it's going to return nothing.

20
00:01:31,010 --> 00:01:34,340
So this is like a void function that you would see in Java, for example.

21
00:01:35,030 --> 00:01:43,190
So in this example here, the arithmetic class has a lambda declared in its constructor with an integer

22
00:01:43,190 --> 00:01:45,470
parameter and a Boolean return type.

23
00:01:45,890 --> 00:01:52,310
And then in the end, its block of the class we pass a value five once the class is initialized.

24
00:01:52,880 --> 00:01:58,340
So we see this is again using a lambda and this time as a parameter.

25
00:01:58,370 --> 00:02:03,530
So you can basically use one does at all different kinds of points of your application.

26
00:02:04,160 --> 00:02:10,310
So another way can be to call a number within a block using the Invoke operator.

27
00:02:10,699 --> 00:02:18,200
So here in this way, we call the method when the button is clicked and you can receive this value at

28
00:02:18,200 --> 00:02:21,560
the point of initializing the arithmetic class.

29
00:02:22,100 --> 00:02:28,790
So we are invoking or calling the same function right here with the value of five, so we're passing

30
00:02:28,790 --> 00:02:29,630
five to it.

31
00:02:30,500 --> 00:02:32,990
So it's here, this some.

32
00:02:34,690 --> 00:02:41,980
OK, now to actually parse an argument or implementation of the lambda, we use curly braces.

33
00:02:42,400 --> 00:02:48,310
So in this arithmetic class will receive the result passed in the init block and then check if the value

34
00:02:48,310 --> 00:02:51,910
is greater than five because it has a Boolean return type.

35
00:02:52,120 --> 00:02:56,830
We have a true or false at the end of each condition block here as well.

36
00:02:58,570 --> 00:03:04,120
So we can also create a method first and then call it with the lumber.

37
00:03:04,840 --> 00:03:11,950
So you see we have this method operation at the top and then we call it using a lambda at the bottom.

38
00:03:12,550 --> 00:03:14,980
OK, so this was all rather theoretical.

39
00:03:15,460 --> 00:03:21,670
Now let's go ahead and see how we can use lambdas in real world examples, in particular in our room

40
00:03:21,670 --> 00:03:22,960
database example.

