-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path#35-High_Order_function.dart
More file actions
34 lines (23 loc) · 976 Bytes
/
#35-High_Order_function.dart
File metadata and controls
34 lines (23 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
void main(){
//Higher order Function
//it is a special function that take function as a parameter or return function or both.
//Calling the Higher order function.
// 1st
Function lFunction = (int total) => print(total);// defining the function.
highFunc("Hello dart", lFunction); //this function will take place of "myfunction"
//2nd
var hfunction = myRFunc(); // assign function to a varriable
print(hfunction(10,20)); //add parameters to the function.
//this will fall in the place myRFunction
//and take the parameter as a parameter of "addition" function because it return the function
}
//function as a function parameter
void highFunc(var message, Function myfunction){ //High order function
print(message);
myfunction(40);
}
//Return a function
Function myRFunc(){//High order function that return function.
Function addition = (int n1, int n2) => n1 + n2; //Here we define a lambda function.
return addition();
}