Please enable JavaScript.
Coggle requires JavaScript to display documents.
JavaScript (Functions (map() (Map function in arrays takes an array and…
JavaScript
Functions
first class functions
allows us to treat functions as data
assign them to variables
pass them to other functions
return them from functions
higher order function
What is higher order function?
any function which takes a function as an argument, returns a function, or both
What is it for?
Abstract or isolate actions, effects, or async flow control using callback functions, promises, monads
Create utilities which can act on a wide variety of data types
Partially apply a function to its arguments or create a curried function for the purpose of reuse or function composition
Take a list of functions and return some composition of those input functions
map()
Map function in arrays takes an array and applies a particular function to all of its elements one by one and returns another array.
Since, we’ll always be getting another array from the map, we can always map it again to create a chain of array transformations . [1,2,3].map(x => x
3).map(x => x
2).map(x => x / 6)
A Map function is more than an iterator function, remember, when our value is inside a container we cannot just directly apply a function on it and expect the value to be changed.
const a = [1, 2, 3]
String(a) = ‘[1 ,2, 3]’ and not [‘1’, ‘2’, ‘3’]
gives a function access to the contents of the container.
never changes the container, instead it just act upon its contents. Keeping the container retained.
will not change the type of the container but it can change the type of its contents.
Containers
Functors
What is Functors?
containers that can be used with ‘map’ function
a container which can be mapped upon by a Unary function.