|
|
|
|
|
by papaver
1205 days ago
|
|
if you enjoy functional programming and are looking for a utility library, ramda has been a joy. very very well thought out. being able to compose functions together and treat data as a stream of information being transformed is incredibly easy. it is also compatible with libraries which implement algebraic structures like fantasy land. coupled with the other r libs its quite fun to program with. just be careful as it gets hairy to read pretty fast if one doesn't understand all the functions that come into play... // pull traits dictionary out of tokens
const extractTraits = R.pipe(
R.map(R.pipe(
R.last,
R.prop('attributes'))),
R.reject(R.isNil),
R.reduce(R.mergeWith(concatValues), {}),
R.map(R.pipe(
R.unless(R.is(Array), R.of),
R.groupBy(R.identity),
R.map(R.count(R.identity)),
R.toPairs,
R.sortBy(R.prop(0)),
R.map(R.zipObj(['name', 'count'])))));
|
|