1 00:00:00,840 --> 00:00:02,080 Hi this is rings at the heart. 2 00:00:02,100 --> 00:00:05,910 And welcome to the next video of this Gharlane programming series. 3 00:00:05,910 --> 00:00:11,070 Now in this video we will talk about high level functions and does expressions. 4 00:00:11,100 --> 00:00:16,650 Now as a beginner you might feel there difficulty to understand these two concepts but I will try to 5 00:00:16,650 --> 00:00:19,570 explain you each and every concept in detail. 6 00:00:19,800 --> 00:00:23,460 So I simply devalue this more deal in some sections. 7 00:00:23,610 --> 00:00:28,920 So in this video we will have the brief introduction of the higher level functions and Londres with 8 00:00:28,920 --> 00:00:34,770 the help of a small Demel in which we will try to implement a code with the help of object oriented 9 00:00:34,860 --> 00:00:37,440 programming we using the interface. 10 00:00:37,440 --> 00:00:41,010 And then we will use how to use the High-Level functions. 11 00:00:41,130 --> 00:00:48,580 And then we will use the land does expressions and in the next video we will talk about the Landau's 12 00:00:48,580 --> 00:00:51,070 and high level functions in the detail. 13 00:00:51,280 --> 00:00:57,540 With the help of explanation as well as Demel So this video is all about the introduction video. 14 00:00:58,000 --> 00:01:01,150 So what are High-Level functions in Cartland now. 15 00:01:01,180 --> 00:01:06,590 In Cartland we have functions that accepts functions as a parameter. 16 00:01:06,940 --> 00:01:13,990 So instead of passing a string or integer we can simply pass a function as a parameter to some other 17 00:01:14,080 --> 00:01:15,000 function. 18 00:01:15,010 --> 00:01:23,360 Right and then from a function we can also return in particular function and also at last we can have 19 00:01:23,360 --> 00:01:30,460 functions that can either accept the functions as a pedometer and return of function as a value. 20 00:01:30,530 --> 00:01:36,660 So if a function can satisfy any of these three criteria then that function is known as the High-Level 21 00:01:36,750 --> 00:01:37,710 functions. 22 00:01:38,500 --> 00:01:40,690 Now next comes the lambdas. 23 00:01:40,690 --> 00:01:44,220 Now the lambdas in a simple words can be defined as. 24 00:01:44,380 --> 00:01:47,540 It is just a function without any name. 25 00:01:47,560 --> 00:01:52,640 Now trust me the concept of High-Level function and the land does is very very important. 26 00:01:52,810 --> 00:01:58,930 If you want to jump into the anthro devlopment with Gartin as a programming language so make sure you 27 00:01:58,930 --> 00:02:05,140 understand all these concepts of high level functions and lambdas in this for the five videos that I'm 28 00:02:05,140 --> 00:02:06,460 going to show you in this. 29 00:02:06,490 --> 00:02:11,240 Marty will so make sure you watch each and every second of this Mordy will. 30 00:02:11,560 --> 00:02:13,560 So excited to indulge your ID. 31 00:02:13,700 --> 00:02:20,420 I'm having a glass program inside which I am having a simple method to add two numbers that takes me 32 00:02:20,440 --> 00:02:27,050 and B as a fit I need to find them and then print the sum right and insert the main function. 33 00:02:27,070 --> 00:02:32,190 I'm simply creating the object of the program and then calling this function. 34 00:02:32,440 --> 00:02:37,570 So if I add in the score right now we get 9 in the output console. 35 00:02:37,570 --> 00:02:38,750 No doubt in Dagh. 36 00:02:39,040 --> 00:02:43,470 Now now the same program can be written with the help of an interface. 37 00:02:43,720 --> 00:02:47,980 That is when we we're going to print though some of these two numbers. 38 00:02:47,980 --> 00:02:54,220 We are simply going to use the interface so far that has defined the interface down the side. 39 00:02:54,220 --> 00:03:00,230 So here I have simply defined my interface with a function of execute that exited and we get off. 40 00:03:00,250 --> 00:03:01,720 Indeed your value. 41 00:03:01,810 --> 00:03:04,270 Let's see some. 42 00:03:04,400 --> 00:03:10,220 If you don't know what is the interface then you can simply call this interface as a listener. 43 00:03:10,220 --> 00:03:13,350 Suppose on click of a button something should happen. 44 00:03:13,370 --> 00:03:14,590 So what should happen. 45 00:03:14,630 --> 00:03:22,150 Be didn't mean the help of this interface but I like an android we have Barton dot on click listener 46 00:03:22,480 --> 00:03:25,940 on each listener on double click listener and so on. 47 00:03:25,960 --> 00:03:29,720 All those are actually of an android or Java. 48 00:03:29,880 --> 00:03:33,940 So similarly I've simply defined the interface having this method of execute. 49 00:03:34,060 --> 00:03:37,740 So let us not proceed forward and let us copy this method. 50 00:03:38,940 --> 00:03:43,480 And pasted and they're called Inside the class program later we change the command line. 51 00:03:43,500 --> 00:03:49,190 So I'm simply going to use the same method and print does some with the help of interface straight. 52 00:03:49,200 --> 00:03:50,890 So here as I told them we don't. 53 00:03:50,960 --> 00:03:52,060 I simply call. 54 00:03:52,200 --> 00:04:00,690 I will simply define their code as legacy action and then the name of the interface as my interface. 55 00:04:00,810 --> 00:04:03,210 Now this is my interface is user defined. 56 00:04:03,210 --> 00:04:08,600 So you can change this name as you wish and this method is also user defined. 57 00:04:08,640 --> 00:04:09,370 Right. 58 00:04:09,690 --> 00:04:16,250 And now inside is where they will do is suppose this print Ellen is actually the body later as you make. 59 00:04:16,320 --> 00:04:16,860 Right. 60 00:04:17,100 --> 00:04:18,010 So he had as well. 61 00:04:18,030 --> 00:04:20,310 This print is actually the body. 62 00:04:20,430 --> 00:04:28,740 So in place of print Ellen what we do is I simply use action d'arte lazy exit and simply pass some as 63 00:04:28,940 --> 00:04:29,810 it did. 64 00:04:30,150 --> 00:04:32,110 And now let us leave this statement. 65 00:04:32,160 --> 00:04:38,310 As of now here and now inside the main method leads straight to call this act two numbers method that 66 00:04:38,310 --> 00:04:41,400 has a third pyramid as the interface. 67 00:04:41,400 --> 00:04:47,490 So what we do is I would simply call program dog act two numbers and I would simply select the second 68 00:04:47,490 --> 00:04:55,680 one that takes three meters to see a 7 and that it will be the interface. 69 00:04:55,680 --> 00:05:02,370 Now if you are from a Java background then you must be knowing that you can not instantiate or create 70 00:05:02,370 --> 00:05:04,290 the object of an interface. 71 00:05:04,440 --> 00:05:06,140 You can never do that. 72 00:05:06,270 --> 00:05:08,450 So how can we use this interface. 73 00:05:08,520 --> 00:05:15,740 So far that ask for a java we need to first create a class that implements this interface. 74 00:05:15,770 --> 00:05:22,270 Right and right after that we can simply implement this method that will be called when this statement 75 00:05:22,330 --> 00:05:24,020 will be executed. 76 00:05:24,040 --> 00:05:30,280 So in case of Java or in Android we used to have new on click listener or something like that. 77 00:05:30,310 --> 00:05:34,440 And inside this we actually used to implement the on click method. 78 00:05:34,460 --> 00:05:41,770 Right but in case of Cartland since we don't have a new keyword that creates the new instance that implements 79 00:05:41,830 --> 00:05:42,930 this interface. 80 00:05:42,940 --> 00:05:50,690 So in place of this we have the object keyword so defined the object keyword followed by a colon then 81 00:05:50,690 --> 00:05:53,170 followed by my interface. 82 00:05:53,180 --> 00:05:59,380 Now here I would simply define the body of this my interface and then hit enter. 83 00:05:59,630 --> 00:06:03,850 Now here it shows some EDR that we need to implement the method. 84 00:06:03,980 --> 00:06:09,450 So simply press oared bliss enter and implement the member and then hit on. 85 00:06:09,470 --> 00:06:11,980 OK so here. 86 00:06:12,150 --> 00:06:12,850 The end. 87 00:06:12,870 --> 00:06:17,560 I already have simply created the execute method for us. 88 00:06:17,590 --> 00:06:19,950 So here we have the overate notation. 89 00:06:20,140 --> 00:06:23,720 So inside this we have to define the method body. 90 00:06:23,740 --> 00:06:27,310 Now our body in our case is different in some. 91 00:06:27,340 --> 00:06:34,990 So simply copy it or got it from here and pasted inside this over didn't execute mattered. 92 00:06:34,990 --> 00:06:38,780 Now if I had the code right now let's see what happens. 93 00:06:40,410 --> 00:06:41,600 So here in the output. 94 00:06:41,620 --> 00:06:43,970 And so we get nine again. 95 00:06:44,010 --> 00:06:50,820 So this shows that by using the object oriented the darkness by using the interface we have simply got 96 00:06:50,820 --> 00:06:58,520 the same output right now let us come to the point now even if you have not understood Vought I have 97 00:06:58,520 --> 00:07:04,350 been here using the interface then please don't worry about it because I mean more to of this video 98 00:07:04,400 --> 00:07:07,580 is to understand the Landau's and high level functions. 99 00:07:07,580 --> 00:07:08,580 Now at the end. 100 00:07:08,690 --> 00:07:09,980 Let us come to the point. 101 00:07:10,000 --> 00:07:15,950 Let us use the Landau's and the high level functions and try to get the sum of these two numbers using 102 00:07:15,950 --> 00:07:16,740 the lambdas. 103 00:07:16,760 --> 00:07:23,600 Right now in order to use a lambda first we have to define a function that is a high level function 104 00:07:23,900 --> 00:07:26,650 that can accept a function within a function. 105 00:07:26,660 --> 00:07:31,170 So let us define new function and then later change the command line. 106 00:07:31,220 --> 00:07:38,720 And now here as I told paramita I won't use this in Duffys I would simply use some lambda expression 107 00:07:38,780 --> 00:07:43,090 that ever talk about it shortly and then we will change the body as well. 108 00:07:43,100 --> 00:07:50,230 Here now here inside the main method we do is I would simply define a London expression. 109 00:07:50,240 --> 00:07:57,440 Now how to define a lambda is the I'd use the curly braces open and close and then you have to define 110 00:07:57,590 --> 00:07:58,540 a variable. 111 00:07:58,700 --> 00:08:07,580 Let's say there Scollard is now followed by a dash forward by Arrow and then the body the body is actually 112 00:08:07,730 --> 00:08:08,790 in line. 113 00:08:08,860 --> 00:08:12,230 So simply copy and paste it here. 114 00:08:13,310 --> 00:08:19,640 An insert of some learned Scollard is Novotny what we have written inside these two curly Blackard are 115 00:08:19,700 --> 00:08:24,450 actually the lambda function or expression. 116 00:08:24,450 --> 00:08:28,560 So the lambda expression is nothing but just a function. 117 00:08:28,590 --> 00:08:35,970 No why do we call it as a function not just because this is actually a function without any name. 118 00:08:35,970 --> 00:08:38,350 Now suppose I have two numbers. 119 00:08:38,370 --> 00:08:41,610 This is a function with a name at two numbers. 120 00:08:41,700 --> 00:08:47,230 But here this lambda expression which is actually the function has no name. 121 00:08:47,310 --> 00:08:50,300 It has just some code written inside it. 122 00:08:50,370 --> 00:08:56,770 Now here this s is actually upbeat data like in a and b. 123 00:08:56,790 --> 00:09:00,120 Here are the meters inside the actual numbers. 124 00:09:00,130 --> 00:09:04,360 Similarly here this is actually acting as a bit. 125 00:09:04,470 --> 00:09:09,710 Then right after this operator of Atto you will find print l n s. 126 00:09:09,750 --> 00:09:13,520 Now this is actually the body of the method right. 127 00:09:13,590 --> 00:09:15,510 Similar to what we have written here. 128 00:09:15,510 --> 00:09:18,720 This is the body of the method of actually numbers. 129 00:09:18,720 --> 00:09:25,710 Similarly print alone is is actually the body of the lambda expression or function. 130 00:09:25,710 --> 00:09:29,540 Now here it shows some error that they were altered shortly so. 131 00:09:29,610 --> 00:09:38,310 But before that he had to learn and define Let's see Val best of their type of string eager to learn 132 00:09:38,370 --> 00:09:39,880 say hello. 133 00:09:40,020 --> 00:09:46,110 So here I've simply defined a variable of test of their type of string equal to some value of Hello. 134 00:09:46,140 --> 00:09:48,180 Right now similar to this. 135 00:09:48,180 --> 00:09:53,850 This lambda expression can also be assigned to some variable such as this. 136 00:09:54,000 --> 00:09:56,720 So here is what we do is I was intrigued to find a val. 137 00:09:56,880 --> 00:10:03,800 Let's see my lambda equal to s followed by the third Borghi. 138 00:10:03,810 --> 00:10:05,930 This is actually the speedometer. 139 00:10:06,180 --> 00:10:08,220 And then we have the meter body. 140 00:10:08,220 --> 00:10:09,310 Don't forget it. 141 00:10:09,390 --> 00:10:13,960 Now the compiler wants to know the type of this as variable. 142 00:10:14,130 --> 00:10:16,630 So this is actually of the type of. 143 00:10:16,650 --> 00:10:20,090 And now here the end will be gone. 144 00:10:20,100 --> 00:10:27,750 Now instead of declaring the S as in we can also define that type of expression to this variable of 145 00:10:27,810 --> 00:10:30,450 my lambda similar to what we have done here. 146 00:10:30,450 --> 00:10:31,650 This is a string Hello. 147 00:10:31,650 --> 00:10:36,800 So we have simply declared that this hello is actually of their type of string. 148 00:10:36,810 --> 00:10:39,070 So this test will not become string. 149 00:10:39,090 --> 00:10:39,430 Right. 150 00:10:39,450 --> 00:10:47,070 So similarly My lambda followed by colon and then what we do is the first one is actually the Meador 151 00:10:47,130 --> 00:10:48,840 which is other type of int. 152 00:10:48,900 --> 00:10:52,470 So here Blackard open and close it will say this. 153 00:10:52,480 --> 00:10:53,690 Let us use I. 154 00:10:53,790 --> 00:10:56,490 And B which is actually the pyramid. 155 00:10:56,880 --> 00:11:04,720 Then followed by Dash Adul and then this print Ellen is now what is the type of the body. 156 00:11:04,950 --> 00:11:09,020 Which means that vort exactly you are returning from this method. 157 00:11:09,060 --> 00:11:14,690 Now since I told you print L.N. is actually the content of the body of this method. 158 00:11:14,820 --> 00:11:20,510 So this print alone method does not return anything it returns void or unique. 159 00:11:20,580 --> 00:11:24,100 So here where they would do is I would simply write unit. 160 00:11:24,350 --> 00:11:32,400 Right now I suppose as a body if we had let's say two plus three which actually returns the interior 161 00:11:32,400 --> 00:11:33,510 value 5. 162 00:11:33,510 --> 00:11:36,980 So here I would simply write and find. 163 00:11:37,200 --> 00:11:44,810 Similarly if we have here let's say hello then this board will actually return the string. 164 00:11:44,820 --> 00:11:47,690 So here insert of and I would simply write string. 165 00:11:47,880 --> 00:11:50,010 Right now here. 166 00:11:50,080 --> 00:11:50,680 Since. 167 00:11:50,700 --> 00:11:53,020 Let us get get back to originality. 168 00:11:53,860 --> 00:11:55,100 We had the print. 169 00:11:55,100 --> 00:11:56,230 Ellen is that simple. 170 00:11:56,240 --> 00:11:57,900 It does nothing. 171 00:11:57,910 --> 00:12:00,030 Which means unit right. 172 00:12:00,130 --> 00:12:03,990 So this completes obvious statement of lambda. 173 00:12:04,010 --> 00:12:07,810 Now Still if you have any doubt then please check out my next video. 174 00:12:07,920 --> 00:12:14,290 I talk about Vought are the content of a lambda expression but as of now and let us proceed ahead. 175 00:12:14,390 --> 00:12:20,110 And now what we do is I simply try to call this function. 176 00:12:20,120 --> 00:12:23,730 Now remember this my lambda is actually a function. 177 00:12:23,860 --> 00:12:32,920 So here if I call let's see a program dord Let's see Act Two numbers and then simply pass to come on 178 00:12:32,980 --> 00:12:33,840 7. 179 00:12:33,850 --> 00:12:37,120 Now they are told pyramided I want to parse this. 180 00:12:37,120 --> 00:12:40,810 My lambda so alert Scollard my lambda. 181 00:12:40,810 --> 00:12:46,870 Since this my lambda is actually the function that we're passing to another function right. 182 00:12:46,930 --> 00:12:54,850 So that is why this function is now acting as a high level function that simply accepts lambda as it 183 00:12:55,010 --> 00:12:55,350 did. 184 00:12:55,540 --> 00:13:00,400 That is a function as it did so here my lambda will fall here. 185 00:13:00,550 --> 00:13:09,340 So here I have to define the name of the variable for this function like Scollard does seem one as action. 186 00:13:09,340 --> 00:13:12,900 So let's see it call action followed by a colon. 187 00:13:12,910 --> 00:13:15,340 Then give it a space and now here. 188 00:13:15,370 --> 00:13:18,630 Since E and B are of their type of integer. 189 00:13:18,910 --> 00:13:26,410 So this action function should also contain some type and DECtape is actually coming from here in nature 190 00:13:27,040 --> 00:13:29,230 followed by unit right. 191 00:13:29,230 --> 00:13:31,630 Come on C and come on we. 192 00:13:32,080 --> 00:13:40,650 So then we pass my lambda which is actually the function coming from and going into unit so we can't 193 00:13:40,650 --> 00:13:44,460 read it as this function action coming from my end. 194 00:13:44,670 --> 00:13:45,890 Do you. 195 00:13:45,960 --> 00:13:50,340 So this unit is actually the return type of disappearing. 196 00:13:50,370 --> 00:13:54,370 Ellen is more value we returning from the body right here. 197 00:13:54,370 --> 00:13:59,830 If you notice inside this method of acting numbers we have the body of print and then some. 198 00:13:59,860 --> 00:14:06,690 Now this Borghi we have already defined inside the print L N S that is inside the land expression. 199 00:14:06,700 --> 00:14:10,790 So what we can do here is begin simply comment that this statement. 200 00:14:11,020 --> 00:14:12,360 And instead of this statement. 201 00:14:12,370 --> 00:14:18,060 I would simply call action as we do to simply pass some. 202 00:14:18,400 --> 00:14:21,010 Now then called will be compiled. 203 00:14:21,010 --> 00:14:30,290 Then this state main action Beira we some will actually be replaced by put into line s. 204 00:14:30,390 --> 00:14:31,110 Right. 205 00:14:31,110 --> 00:14:33,190 So what we're doing here is this. 206 00:14:33,210 --> 00:14:41,580 Some will now be substituted by this as and this as it is going into the body of the line s. 207 00:14:41,640 --> 00:14:46,770 So here we are simply getting the some trend line some are just to avoid confusion. 208 00:14:46,770 --> 00:14:48,560 Let us call Parentline some. 209 00:14:48,600 --> 00:14:55,950 So when the code will be compiled the actions will actually be converted to disappearing lines and in 210 00:14:56,040 --> 00:15:00,350 outpoured we will get the sum of a and b that is 9. 211 00:15:00,480 --> 00:15:01,570 So let us not in the code. 212 00:15:01,570 --> 00:15:03,050 And let's see what happens. 213 00:15:05,190 --> 00:15:08,290 So the output and so will we again get 9. 214 00:15:08,310 --> 00:15:11,340 So this shows that our record is now working perfectly fine. 215 00:15:11,370 --> 00:15:17,490 Again with the help of High-Level function with lambda as paramita now we can simply remove this quarter 216 00:15:17,490 --> 00:15:18,340 from here. 217 00:15:18,570 --> 00:15:25,260 So here in front of you I have simply shown you a very simple way and then using the interface or the 218 00:15:25,260 --> 00:15:26,990 object oriented way. 219 00:15:27,120 --> 00:15:33,650 And then finally the comparison of these two metrics with the High-Level functions with lambda as fearmonger. 220 00:15:33,780 --> 00:15:41,070 Now at the end I will simply conclude this video by simply telling you that we can directly put this 221 00:15:41,190 --> 00:15:46,730 Londa expression control X or Control-C in place of this. 222 00:15:46,770 --> 00:15:48,480 My lambda very well. 223 00:15:48,720 --> 00:15:54,520 So when this statement will be executed we're simply passing the land the expression varity. 224 00:15:54,720 --> 00:15:58,120 But earlier we using the my lambda variable. 225 00:15:58,260 --> 00:16:00,280 So the code will execute fine. 226 00:16:00,360 --> 00:16:06,000 Now again at last you must be thinking if we were able to achieve the same thing with the help of this 227 00:16:06,060 --> 00:16:12,750 simple method and by using the interface as well then why do we need to have this lambda expression 228 00:16:12,780 --> 00:16:14,240 and High-Level functions. 229 00:16:14,310 --> 00:16:20,310 But trust me then you will enter into the Android application development you will be surrounded by 230 00:16:20,400 --> 00:16:23,510 lambda expressions and high level functions all around. 231 00:16:23,670 --> 00:16:30,150 So for that you have to simply clear your concept about these two concepts right here only and in case 232 00:16:30,180 --> 00:16:35,130 you have not understood the London expression and High-Level function in this video then please check 233 00:16:35,130 --> 00:16:36,560 out my next video. 234 00:16:36,700 --> 00:16:40,290 I will talk about these two concepts in detail. 235 00:16:40,600 --> 00:16:42,450 This is shades of the art signing off. 236 00:16:42,570 --> 00:16:43,640 And thanks for watching. 237 00:16:43,650 --> 00:16:44,570 Have a good day. 238 00:16:44,730 --> 00:16:45,500 Thank you.