In Functional Programming, functions are treated as values. Just like, we can assign a value to any variable, in the same way we can assign functions to variables. And also, we can pass a function as an argument and return a function (the same behaviour that exists with values).
A higher-order function is a function that can take another function as an argument, or that returns a function as a result.
Aim is to make your code composable.
In programming languages, when you are able to pass, return and assign a type, that type is considered to be a first class citizen.
Types inside of Javascript are first class citizens, we are able to assign, pass and return all the different types in JS.
map is used to transform values inside an array and put
them into another array.
Whereas, filter only returns a filtered array. It doesn't do
any modification.
Refer to this for more info on Promises.
Q. What are they?
A. See this
Objects that implement functions like map are called as functors.
It is not the function, but the object to which we refer as functor.
The 3 rules which determine what is a functor and what's not:
- Transformation of content
- It maintains the structure (for example in Array.map, the size and the structure of the Array remains exactly the same).
- Return a new functor.
P.S. Functors also need to be able to contain any type. They need to be generic in nature.
For more, please refer here