rjhilgefort
11/10/2017 - 4:25 AM

keyBy.js

// 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)
)