Higher Order Function | Lambda Function | In Flutter. Flutter Important Interview Question.

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone welcome back to my channel in this video I'll be talking about higher order functions if you are attending any interview higher order functions Lambda function these are the Hot Topics which interviewer will going to ask if you are attending any interview for flutter developer so in that we can pass function to other function as a parameter or we can return function from a function as the return value so these are the properties of higher order functions we can use functions as first class object so let's understand the concept of higher order function and Lambda functions in this video so without any delay let's get started right after this [Music] intro so this is the dotpad and this is the main function and I have created a another function by the name add num and as a parameter list of numbers and there is another parameter which is a function so what is higher order function in higher order function you can pass function as I told you in the beginning that you can pass function inside a function through parameters or you can return so here I'm passing a function now after that I'm creating a variable sum which is initialized by zero and I'm using for Loop initializing value k equal to0 and K less than equal to the numbers array that we will provide do length k++ and inside this I'm using sum and the total number of the list that I'm providing here will be calculated and pass to the sum and here normally what we do here is the void that it doesn't return anything so if we want to return any value or data then we can return from here for now it will return integer value so normally we would return integer value from here but now what I will do I will not return anything instead of that I'm using this function Sam results and passing the value sum here and now I'll call this function add num in my main function so first of all add num it has two parameters like numbers and a function so let me create a list num list and let me provide some value 6 8 4 10 and second parameter would be a function so for that I will have to create a function let me name it like add print sum print sum and let me add it here now the error has gone and I'm providing exact parameters that is required by this add num function so first of all this is list and this is function and there is one more thing that I'll will have to pass a parameter also here so for this I will have to declare a variable by the name sum and we print the value now if I'll run this it will print total sum of this array so here I'm passing function inside a function as a parameters so now what I will do I'll remove this function and instead of that I'm creating function at print sum this is the parameters that I'm passing here for now I'm using one parameter because here the function that I'm passing inside this add num function is using only one parameter that is why I'm passing here one it depends upon your situation or it depends upon the function that you're creating that how many parameters are there you can add as many as parameters separated by commas so after that it will return the function methods for now I'm just printing the Valu so print sum and semicolon now let me run this so result will be same so I have created function like this so that you can understand what is Lambda function or Anonymous function so till now we have discussed higher order function and Lambda function so proper definition of Lambda function is that a function which doesn't have any name so here what it is this is a parameter of the function and the function is starting from here and there is no name so this kind of function is known as Anonymous function or Lambda function or you can do one more thing instead of function you can use here bar and it will also work so here we have discussed almost three things higher order function Lambda function the point that I have discussed in the beginning of the video that we can use function as first class object so here this is my main function and here I'm using function of this class as an object also in Lambda function or Anonymous function for now there is only single line of code so if there are multiple instructions that you will have to perform in this function so for that you can use curly braces first you will have to remove that equal to less than sign and then you will have to add curly bres and inside this this is the curly bres and inside this you can perform several things multiple line of code so here I'm using like the sum is and after that let me print the value as you can see now it is printing this is sum and the number is 28 so inside Lambda function if there is only one line of code then you can use uh that return operator for that otherwise you can use this curly braces and you can perform several tasks for that particular function so in the beginning of the video I have told you one more property of higher order function that a function will also return a function will be considered as higher order function so for that I'm creating another function and its return return type is function so function and and I'm naming this like return return text name of the function is return return text inside this curly braces I'm returning a function so with the help of this small Braes and then inside this curly braces and you will also have to add semicolon and I'll print my instruction like returning higher order function so this is the function which is returning another function so now let me call this function inside main function return text now here is the twist let me call this this is the function return text let me run so it is not printing the value it is printing that 28 the sum of the list only it is not returning or printing this value because higher order function or a function inside a function will be called like return text parenthesis and again we will have to add extra parenthesis for calling this method now when we run this this is the text which is coming from this function hope you have learned something new in this video and if you do then please like the video and subscribe to my channel and stay connected with us for such kind of informative videos in future that's it in the video hope to see you next time in our next video bye for now hey thanks for watching let's turn the Subscribe button into a friendship button and if you enjoy the content that I create I would be honored to have you as a subscriber your support keeps this adventure alive and if you do have any query you can comment below and till then keep coding keep supporting we'll meet you in the next video till then take care
Info
Channel: thecodeme
Views: 715
Rating: undefined out of 5
Keywords: flutter, flutter tutorial, flutter for beginners, flutter animation, flutter app development, dart language, easy UI with flutter, learn with flutter, make app with flutter, package of the week flutter, flutter package of the week, flutter design of the week, flutter user interface, higher order function, higher order function in flutter, lambada function in flutter, flutter interview question
Id: mRK3J9j1Oak
Channel Id: undefined
Length: 10min 25sec (625 seconds)
Published: Wed Jan 31 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.