These are chat archives for ramda/ramda

26th
Oct 2018
Martin Harvan
@kane77
Oct 26 2018 10:07
Different question.. I have {foo: {bar: 1}} and {foo: {prop: 1}} , how do I merge these so that it's {foo: {bar: 1, config: {prop: 1}}}?
Riku Tiira
@rikutiira
Oct 26 2018 10:20
Here’s how I’d approach it @kane77
// v1, this would apply same config pattern to all properties
R.mergeWith((v1, v2) => R.merge(v1, { config: v2 }),  o, o2)

// v2, foo specific:
const lens = R.lensProp(‘foo’)
R.over(lens, R.merge({ config: R.view(lens, o2) }), o1)
Martin Harvan
@kane77
Oct 26 2018 11:27
@rikutiira thanks a lot.. the first thing is what I'm after..
Martin Harvan
@kane77
Oct 26 2018 12:31
actually one more question.. how would it be possible to use it in this instead of configMapping?
const mapConfig = R.compose(
  R.values,
  R.flip(R.pick)(configMapping),
  R.keys
)
so what I'm trying to do is for all keys in config object get the value in configMapping for that key and add value config as config prop
sure, I can do it like this:
const mapConfig = (config) => {
  const configViewE = R.mergeWith((v1, v2) => R.merge(v1, { config: v2 }),  configView)(config)
  return R.compose(
    R.values,
    R.flip(R.pick)(configViewE),
    R.keys
  )(config)
}
Martin Harvan
@kane77
Oct 26 2018 12:37
but that does not seem very nice