Skip to content

Instantly share code, notes, and snippets.

@stepankuzmin
Last active December 19, 2016 12:35
Show Gist options
  • Save stepankuzmin/a84f8312dee18c135f435553414cc76b to your computer and use it in GitHub Desktop.
Save stepankuzmin/a84f8312dee18c135f435553414cc76b to your computer and use it in GitHub Desktop.
My Ramda helpers
const R = require('ramda');
const mapIndexed = R.addIndex(R.map);
// notEmpty : a -> Bool
const notEmpty = R.converge(R.compose(R.not, R.or), [isNaN, R.isEmpty]);
// buildDict : String -> [{ k: v }] -> { k: v }
const buildDict = R.uncurryN(2, key => R.pipe(
R.map(R.compose(R.toLower, R.prop(key))),
R.uniq,
R.filter(R.compose(R.not, R.isEmpty)),
mapIndexed(R.flip(R.objOf)),
R.mergeAll
));
// pickByRegExp : RegExp -> Object -> Object
const pickByRegExp = RegExp => R.pickBy(R.compose(R.test(RegExp), R.nthArg(1)));
// featurePropertyLens : Int -> String -> Lens s a
const featurePropertyLens = (index, property) => R.compose(
R.lensProp('features'),
R.lensIndex(index),
R.lensPath(['properties', property])
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment