Skip to content

Instantly share code, notes, and snippets.

@rjhilgefort
Last active November 10, 2017 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjhilgefort/bbd55293bb7a8d6c111f8f3515dc4b58 to your computer and use it in GitHub Desktop.
Save rjhilgefort/bbd55293bb7a8d6c111f8f3515dc4b58 to your computer and use it in GitHub Desktop.
// NOTE: Ramda repl
console.clear()
const foo = [
{ id: 'one' },
{ id: 'two' },
{ id: 'three' },
]
const keyBy_point = getter => data =>
reduce(
(acc, val) => assoc(getter(val), val, acc),
{},
)(data)
const keyBy_pointFree = getter =>
reduce(
pipe(
unapply(identity),
converge(append, [last, identity]),
reverse,
apply(useWith(assoc, [getter, identity, identity])),
),
{},
)
console.log(
keyBy_point(prop('id'))(foo),
keyBy_pointFree(prop('id'))(foo)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment