Last active
December 19, 2016 12:35
-
-
Save stepankuzmin/a84f8312dee18c135f435553414cc76b to your computer and use it in GitHub Desktop.
My Ramda helpers
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
| 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