These are chat archives for ramda/ramda

Apr 2018
Mike Lambert
Apr 15 2018 01:38
Apr 15 2018 15:04
Hi, I have the next list:
[{user: 'a', foo: 'bar'}, {user: 'a', foo: 'buz'}]
I want convert to:
[{user: 'a', foo: ['bar', 'buz']}]
what is the best function for that?
Mike Lambert
Apr 15 2018 15:09
hmm, maybe R.mergeWith or R.mergeWithKey
Apr 15 2018 15:12
thanks, i will try
Mike Lambert
Apr 15 2018 15:14
i wonder if R.groupBy could be used...
you'll also probably need to use them with R.reduce if you want to do this for the whole list
this is a tricky one though...
const users = [
  { user: "a", foo: "bar" },
  { user: "a", foo: "buz" },
  { user: "b", foo: "bar" }

const reducer = R.mergeWithKey(
  (k, l, r) => k == "foo" ? R.concat([l], [r]) : r

R.compose(, [])),
there might be a more elegant way, but this does it
Mike Lambert
Apr 15 2018 15:27
it's unclear what if user b should be { user: "b", foo: "bar" } or { user: "b", foo: ["bar"] }