Hi this is rings at the heart.
And welcome to the next video of this Gharlane programming series.
Now in this video we will talk about high level functions and does expressions.
Now as a beginner you might feel there difficulty to understand these two concepts but I will try to
explain you each and every concept in detail.
So I simply devalue this more deal in some sections.
So in this video we will have the brief introduction of the higher level functions and Londres with
the help of a small Demel in which we will try to implement a code with the help of object oriented
programming we using the interface.
And then we will use how to use the High-Level functions.
And then we will use the land does expressions and in the next video we will talk about the Landau's
and high level functions in the detail.
With the help of explanation as well as Demel So this video is all about the introduction video.
So what are High-Level functions in Cartland now.
In Cartland we have functions that accepts functions as a parameter.
So instead of passing a string or integer we can simply pass a function as a parameter to some other
function.
Right and then from a function we can also return in particular function and also at last we can have
functions that can either accept the functions as a pedometer and return of function as a value.
So if a function can satisfy any of these three criteria then that function is known as the High-Level
functions.
Now next comes the lambdas.
Now the lambdas in a simple words can be defined as.
It is just a function without any name.
Now trust me the concept of High-Level function and the land does is very very important.
If you want to jump into the anthro devlopment with Gartin as a programming language so make sure you
understand all these concepts of high level functions and lambdas in this for the five videos that I'm
going to show you in this.
Marty will so make sure you watch each and every second of this Mordy will.
So excited to indulge your ID.
I'm having a glass program inside which I am having a simple method to add two numbers that takes me
and B as a fit I need to find them and then print the sum right and insert the main function.
I'm simply creating the object of the program and then calling this function.
So if I add in the score right now we get 9 in the output console.
No doubt in Dagh.
Now now the same program can be written with the help of an interface.
That is when we we're going to print though some of these two numbers.
We are simply going to use the interface so far that has defined the interface down the side.
So here I have simply defined my interface with a function of execute that exited and we get off.
Indeed your value.
Let's see some.
If you don't know what is the interface then you can simply call this interface as a listener.
Suppose on click of a button something should happen.
So what should happen.
Be didn't mean the help of this interface but I like an android we have Barton dot on click listener
on each listener on double click listener and so on.
All those are actually of an android or Java.
So similarly I've simply defined the interface having this method of execute.
So let us not proceed forward and let us copy this method.
And pasted and they're called Inside the class program later we change the command line.
So I'm simply going to use the same method and print does some with the help of interface straight.
So here as I told them we don't.
I simply call.
I will simply define their code as legacy action and then the name of the interface as my interface.
Now this is my interface is user defined.
So you can change this name as you wish and this method is also user defined.
Right.
And now inside is where they will do is suppose this print Ellen is actually the body later as you make.
Right.
So he had as well.
This print is actually the body.
So in place of print Ellen what we do is I simply use action d'arte lazy exit and simply pass some as
it did.
And now let us leave this statement.
As of now here and now inside the main method leads straight to call this act two numbers method that
has a third pyramid as the interface.
So what we do is I would simply call program dog act two numbers and I would simply select the second
one that takes three meters to see a 7 and that it will be the interface.
Now if you are from a Java background then you must be knowing that you can not instantiate or create
the object of an interface.
You can never do that.
So how can we use this interface.
So far that ask for a java we need to first create a class that implements this interface.
Right and right after that we can simply implement this method that will be called when this statement
will be executed.
So in case of Java or in Android we used to have new on click listener or something like that.
And inside this we actually used to implement the on click method.
Right but in case of Cartland since we don't have a new keyword that creates the new instance that implements
this interface.
So in place of this we have the object keyword so defined the object keyword followed by a colon then
followed by my interface.
Now here I would simply define the body of this my interface and then hit enter.
Now here it shows some EDR that we need to implement the method.
So simply press oared bliss enter and implement the member and then hit on.
OK so here.
The end.
I already have simply created the execute method for us.
So here we have the overate notation.
So inside this we have to define the method body.
Now our body in our case is different in some.
So simply copy it or got it from here and pasted inside this over didn't execute mattered.
Now if I had the code right now let's see what happens.
So here in the output.
And so we get nine again.
So this shows that by using the object oriented the darkness by using the interface we have simply got
the same output right now let us come to the point now even if you have not understood Vought I have
been here using the interface then please don't worry about it because I mean more to of this video
is to understand the Landau's and high level functions.
Now at the end.
Let us come to the point.
Let us use the Landau's and the high level functions and try to get the sum of these two numbers using
the lambdas.
Right now in order to use a lambda first we have to define a function that is a high level function
that can accept a function within a function.
So let us define new function and then later change the command line.
And now here as I told paramita I won't use this in Duffys I would simply use some lambda expression
that ever talk about it shortly and then we will change the body as well.
Here now here inside the main method we do is I would simply define a London expression.
Now how to define a lambda is the I'd use the curly braces open and close and then you have to define
a variable.
Let's say there Scollard is now followed by a dash forward by Arrow and then the body the body is actually
in line.
So simply copy and paste it here.
An insert of some learned Scollard is Novotny what we have written inside these two curly Blackard are
actually the lambda function or expression.
So the lambda expression is nothing but just a function.
No why do we call it as a function not just because this is actually a function without any name.
Now suppose I have two numbers.
This is a function with a name at two numbers.
But here this lambda expression which is actually the function has no name.
It has just some code written inside it.
Now here this s is actually upbeat data like in a and b.
Here are the meters inside the actual numbers.
Similarly here this is actually acting as a bit.
Then right after this operator of Atto you will find print l n s.
Now this is actually the body of the method right.
Similar to what we have written here.
This is the body of the method of actually numbers.
Similarly print alone is is actually the body of the lambda expression or function.
Now here it shows some error that they were altered shortly so.
But before that he had to learn and define Let's see Val best of their type of string eager to learn
say hello.
So here I've simply defined a variable of test of their type of string equal to some value of Hello.
Right now similar to this.
This lambda expression can also be assigned to some variable such as this.
So here is what we do is I was intrigued to find a val.
Let's see my lambda equal to s followed by the third Borghi.
This is actually the speedometer.
And then we have the meter body.
Don't forget it.
Now the compiler wants to know the type of this as variable.
So this is actually of the type of.
And now here the end will be gone.
Now instead of declaring the S as in we can also define that type of expression to this variable of
my lambda similar to what we have done here.
This is a string Hello.
So we have simply declared that this hello is actually of their type of string.
So this test will not become string.
Right.
So similarly My lambda followed by colon and then what we do is the first one is actually the Meador
which is other type of int.
So here Blackard open and close it will say this.
Let us use I.
And B which is actually the pyramid.
Then followed by Dash Adul and then this print Ellen is now what is the type of the body.
Which means that vort exactly you are returning from this method.
Now since I told you print L.N. is actually the content of the body of this method.
So this print alone method does not return anything it returns void or unique.
So here where they would do is I would simply write unit.
Right now I suppose as a body if we had let's say two plus three which actually returns the interior
value 5.
So here I would simply write and find.
Similarly if we have here let's say hello then this board will actually return the string.
So here insert of and I would simply write string.
Right now here.
Since.
Let us get get back to originality.
We had the print.
Ellen is that simple.
It does nothing.
Which means unit right.
So this completes obvious statement of lambda.
Now Still if you have any doubt then please check out my next video.
I talk about Vought are the content of a lambda expression but as of now and let us proceed ahead.
And now what we do is I simply try to call this function.
Now remember this my lambda is actually a function.
So here if I call let's see a program dord Let's see Act Two numbers and then simply pass to come on
7.
Now they are told pyramided I want to parse this.
My lambda so alert Scollard my lambda.
Since this my lambda is actually the function that we're passing to another function right.
So that is why this function is now acting as a high level function that simply accepts lambda as it
did.
That is a function as it did so here my lambda will fall here.
So here I have to define the name of the variable for this function like Scollard does seem one as action.
So let's see it call action followed by a colon.
Then give it a space and now here.
Since E and B are of their type of integer.
So this action function should also contain some type and DECtape is actually coming from here in nature
followed by unit right.
Come on C and come on we.
So then we pass my lambda which is actually the function coming from and going into unit so we can't
read it as this function action coming from my end.
Do you.
So this unit is actually the return type of disappearing.
Ellen is more value we returning from the body right here.
If you notice inside this method of acting numbers we have the body of print and then some.
Now this Borghi we have already defined inside the print L N S that is inside the land expression.
So what we can do here is begin simply comment that this statement.
And instead of this statement.
I would simply call action as we do to simply pass some.
Now then called will be compiled.
Then this state main action Beira we some will actually be replaced by put into line s.
Right.
So what we're doing here is this.
Some will now be substituted by this as and this as it is going into the body of the line s.
So here we are simply getting the some trend line some are just to avoid confusion.
Let us call Parentline some.
So when the code will be compiled the actions will actually be converted to disappearing lines and in
outpoured we will get the sum of a and b that is 9.
So let us not in the code.
And let's see what happens.
So the output and so will we again get 9.
So this shows that our record is now working perfectly fine.
Again with the help of High-Level function with lambda as paramita now we can simply remove this quarter
from here.
So here in front of you I have simply shown you a very simple way and then using the interface or the
object oriented way.
And then finally the comparison of these two metrics with the High-Level functions with lambda as fearmonger.
Now at the end I will simply conclude this video by simply telling you that we can directly put this
Londa expression control X or Control-C in place of this.
My lambda very well.
So when this statement will be executed we're simply passing the land the expression varity.
But earlier we using the my lambda variable.
So the code will execute fine.
Now again at last you must be thinking if we were able to achieve the same thing with the help of this
simple method and by using the interface as well then why do we need to have this lambda expression
and High-Level functions.
But trust me then you will enter into the Android application development you will be surrounded by
lambda expressions and high level functions all around.
So for that you have to simply clear your concept about these two concepts right here only and in case
you have not understood the London expression and High-Level function in this video then please check
out my next video.
I will talk about these two concepts in detail.
This is shades of the art signing off.
And thanks for watching.
Have a good day.
Thank you.