Skip to content

Instantly share code, notes, and snippets.

@leongaban
Created September 1, 2016 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leongaban/dd5886133636ffd9b2a75586f1b44683 to your computer and use it in GitHub Desktop.
Save leongaban/dd5886133636ffd9b2a75586f1b44683 to your computer and use it in GitHub Desktop.
Utility service using the Ramda functional programming library
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