Created
September 1, 2016 15:54
-
-
Save leongaban/dd5886133636ffd9b2a75586f1b44683 to your computer and use it in GitHub Desktop.
Utility service using the Ramda functional programming library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Utility() { | |
const addOne = n => n + 1; | |
const notEmpty = R.compose(R.not, R.isEmpty); | |
const notIdentical = R.compose(R.not, R.identical); | |
const changeKeyName = R.curry((from, to, object) => { | |
const content = object[from]; | |
const property = R.lensProp(to); | |
const addProperty = R.set(property, content); | |
const removeProperty = R.omit([from]); // Ramda omit needs an Array type to work properly | |
const swapProperty = R.compose(removeProperty, addProperty); | |
return swapProperty(object); | |
}); | |
//////////////////////////////////////////////////////////////////////////// | |
return { | |
addOne : addOne, | |
notEmpty : notEmpty, | |
notIdentical : notIdentical, | |
changeKeyName : changeKeyName | |
}; | |
} | |
module.export = utility; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment