DEV Community

Discussion on: The beauty of Functional Programming

Collapse
 
vonheikemen profile image
Heiker

Another important thing that functional programming encourage is function composition. Even the most simple function can be useful if you combine it with something else.

This is one example that I really like. Say that you have this function.

function identity(arg) {
  return arg;
}

It may seen useless but if you have map function that works like Array.map but for "plain" objects, you could implement a shallow_copy function like this.

function shallow_copy(obj){
  return map(identity, obj);
}
Collapse
 
fannyvieira profile image
Fanny

Yes, this is a nice example, I agree. And i will explain more about this, in the next posts