These are chat archives for ramda/ramda

5th
Feb 2018
Luis Felipe López G.
@luishendrix92
Feb 05 2018 00:59
it does work
because it doesn't compare by a simple ===
it uses its own equality function that works on arrays too
Brad Compton (he/him)
@Bradcomp
Feb 05 2018 16:32
@jay-jlm R.assocPath can create a path if it doesn't exist yet
@ram-bot
R.assocPath(['a', 'b', 'c'], true, {});
ram-bot
@ram-bot
Feb 05 2018 16:33
{ a: { b: { c: true } } }
Tomáš Konrády
@tommmyy
Feb 05 2018 17:27
@jay-jlm in addition what @Bradcomp said, you can use https://ramda-extension.firebaseapp.com/docs/#assocDotPath instead of assocPath if you need dot notation
Gabe Trinidad
@ArchangelGabriel
Feb 05 2018 19:15

Hello can anyone point me to the right direction with this problem that I have,

Basically I have a function that takes in an object and destructures them.

({ data: { accounts, loading } }) => ({
  accounts,
  loading,
})

I would like to make a ramda function that takes in a list of paths, deeply extracts the value from the object and returns an object out of it.

Achieving the same functionality above, I'd like to use the function like this:

deepExtract(['data.accounts', 'data.loading'])
// input: { data: { accounts: 1, loading: 1 } }
// output: { accounts: 1, loading: 1 } (notice the keys doesn't have `data` in it.)

Current progress:

R.pipe(
  R.map(R.split('.')), // <-- gives me a list that I can feed into lensPath [['data', 'accounts'], ['data', 'loading']
  /*  Can't figure out next steps but I'd like to run each of the list to:
   *  1. lensProp
   *  2. merge
   */
)(['data.accounts', 'data.loading'])
Brad Compton (he/him)
@Bradcomp
Feb 05 2018 20:40
Hey @ArchangelGabriel , here's the first solution I could come up with. It doesn't use lenses or merge, but it gets the job done: https://goo.gl/taKrCP
Probably should flip the parameter order for solution
William Carroll
@wpcarro
Feb 05 2018 21:16
In Elixir, there's a function Map.take(map, ["name", "age", "address"]) that'll return a subset of a map. I imagine Ramda has a similar function, but I'm having trouble finding it... does it exist?
Brad Compton (he/him)
@Bradcomp
Feb 05 2018 21:16
R.pick
William Carroll
@wpcarro
Feb 05 2018 21:17
Ah yes! That's the one. Many thanks... any idea where the name came from?
Haskell? I've used Clojure, Erlang, and Elixir and haven't seen pick in those
Brad Compton (he/him)
@Bradcomp
Feb 05 2018 21:39
I don't know if it comes from prior art or just because it makes sense
Tomáš Konrády
@tommmyy
Feb 05 2018 21:39
@ArchangelGabriel
here is mine solution: https://goo.gl/EUbUoZ