These are chat archives for ramda/ramda

13th
May 2018
Stephen Niemans
@stephenniemans
May 13 2018 01:08
@klequis I'm sure there are many ways of doing it, but here's another :)
const getNewState = (state, {_id, field, value}) => {
  const isMatch     = R.propEq('_id', _id)
  const updateValue = R.assoc(field, value)
  const updatePhone = R.map(p => isMatch(p) ? updateValue(p) : p)
  return R.assoc('phone', updatePhone(state.phone), state)
}

console.log(getNewState(state, payload))
Vesa Karvonen
@polytypic
May 13 2018 07:56

@klequis With Partial Lenses you could do something like this:

const update = ({field, value, _id}, state) =>
  L.set(['phone', L.find(R.whereEq({_id})), field], value, state)

Here is the example in a playground.

klequis
@klequis
May 13 2018 21:45
@polytypic That is much cleaner. Thank you!
@stephenniemans Like your solution as well - Thank you!
Stephen Niemans
@stephenniemans
May 13 2018 21:47
you're welcome, I tried to keep it a bit close to your original approach but with some of the Ramda functions thrown in :)
That partial lenses library looks insanely powerful
But also like it will take some work to grasp for me
klequis
@klequis
May 13 2018 21:50
Yes, when I first skimmed the Partial Lenses readme it seemed beyond reach and making wider use of it looks like an investment, but I do think I get Vesa's example. Not going to use until I have time to think/learn about it though.
Stephen Niemans
@stephenniemans
May 13 2018 21:52
If manipulating deeply nested objects ever becomes a commonly recurring part of my tasks I will invest in it most likely but for now I have a lot of other things to learn haha
I think for basic use of lenses the ones that come with Ramda should hopefully help me along enough
verilog15
@verilog15
May 13 2018 21:59
someone here knows Standard ML for a few questions?