Last active
April 23, 2020 12:15
-
-
Save arbaaz/d8f4cce984916bb9739807b86e9505cc to your computer and use it in GitHub Desktop.
Collection of ramda extra
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
export const isNotEmpty = R.complement(R.isEmpty); | |
export const isNotNil = R.complement(R.isNil); | |
export const isTruthy = R.both(isNotEmpty, isNotNil); | |
export const findObject = R.curry((predicate, filterableObject) => { | |
return R.reduce( | |
(acc, key) => { | |
if (predicate(filterableObject[key])) { | |
return R.reduced(filterableObject[key]); | |
} | |
return acc; | |
}, | |
{}, | |
Object.keys(filterableObject) | |
); | |
}); | |
export const filterObjectToList = R.curry((predicate, filterableObject) => { | |
return R.reduce( | |
(acc, key) => { | |
if (predicate(filterableObject[key])) { | |
acc.push(filterableObject[key]); | |
} | |
return acc; | |
}, | |
[], | |
Object.keys(filterableObject) | |
); | |
}); |
Author
arbaaz
commented
Apr 19, 2018
const anyNil = R.any(R.isNil)
if(anyNil([name, age, gender]){
throw new Error('undefined values)'
}
const data = [{ name: 'coinbase', symbol: 'btcusd'}, {name: 'bitstamp', symbol:'ethbtc'}]
R.groupBy(R.prop('symbol'), data);
// Output:
//{"btcusd": [{"name": "coinbase", "symbol": "btcusd"}], "ethbtc": [{"name": "basecampe", "symbol": "ethbtc"}]}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment