Skip to content

Instantly share code, notes, and snippets.

@arbaaz
Last active April 23, 2020 12:15
Show Gist options
  • Save arbaaz/d8f4cce984916bb9739807b86e9505cc to your computer and use it in GitHub Desktop.
Save arbaaz/d8f4cce984916bb9739807b86e9505cc to your computer and use it in GitHub Desktop.
Collection of ramda extra
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)
);
});
@arbaaz
Copy link
Author

arbaaz commented Aug 13, 2018

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