const compose = (f, g) => x => f(g(x))const compose = (f, g, h, i, j) => x => f(g(h(i(j(x)))))const orderByAge = sortBy(prop('age'));
const getOlderCat = last,
const getColor = prop('color')const myCats = [
{
name: 'Misis',
color: 'white',
age: 7
}, {
name: 'Txomsko',
color: 'black',
age: 4
}, {
name: 'Hermes',
color: 'grey',
age: 5
}
]whiteoderByAgegetOlderCatgetColorconst myOrderedCats = sortBy(prop('age'), myCats);
const myOlderCat = last(myOrderedCats);
const myOlderCatColor = prop('color', myOlderCat);const getMyOlderCatColor = x => prop('color',last(sortBy(prop('age'))))(x);const getMyOlderCatColor = compose(prop('color'), last, sortBy(prop('age')))const composedF1 = (f, g, h) => compose(f, g, h);
const composedF2 = (f, g, h) => compose(f, compose(g, h));
const composedF3 = (f, g, h) => compose(compose(f, g), h);
composedF3 = composedF2 = composedF1
const addFive = x => x + 5;
const addTwo = x => x + 2;
const addSeven = x => x + 7;
const composedF1 = compose(addSeven, addTwo, addFive);
// x => x + 14;
const composedAddFiveAndTwo = compose(addTwo, addFive);
// x => x + 7;
const composedF2 = compose(addSeven, composedAddFiveAndTwo);
// x => x + 14;
const composedAddTwoAndSeven = conpose(addSeven, addTwo);
// x => x + 9;
const composedF3 = compose(composedAddTwoAndSeven, addFive);
// x => x + 14;
oderByAgegetOlderCatgetColoroderByAgegetOlderCatgetColoroderByAgegetOlderCatgetColorconst getMyCatCapitalName = cat => cat.name.toUppperCase();
const getCapitalName = compose(toUpperCase, prop('name'));
Algunas veces puede ofuscar el código
const trace = curry((tag, x) => {
console.log(tag, x);
return x;
})oderByAgegetOlderCatgetColortrace('oldest cat'){
name: 'misis',
age: 7,
color: 'white'
}La currificación y aplicación parcial nos permiten preparar cada función para coger su "data" operar sobre él y pasarlo al siguiente eslabón
const prop = curry((prop, obj) => obj[prop]);
const getColor = prop('color')