DEV Community

Cover image for Higher Order Functions
Anin Arafath
Anin Arafath

Posted on

 

Higher Order Functions

What Is Higher order function?
In dart programming language can accept a function as an argument, this type of functions is called higher order functions.

for example :-

void printUser(String Function() getUser)
{
    // getting user maybe it's from api like etc.
    String user = getUser();

   // and print the user.
    print(user);
  }
Enter fullscreen mode Exit fullscreen mode

Here the PrintUser is a higher order function because printUser function is accept a function named getUser as an argument, that void printUser(String Function() getUser){ }.

The functions are first class citizens in dart programming language because, They can be assigned to a variable, passed as an argument to another function, returned from a function, stored in other Data collections, and created in any scope.

What is callback function?


// this function called higher order function.
void higherOrderFunction(String Function() callbackFunction)
{

  // this function called callback function generally.
  callbackFunction();

 }
Enter fullscreen mode Exit fullscreen mode

A function passed as the argument of another function , this kind of function is called callback functions and which function is accepted the callback function that function is called higher order function.

Top comments (0)