These are chat archives for ramda/ramda

1st
Aug 2017
Aaron Mc Adam
@aaronmcadam
Aug 01 2017 10:35
hi everyone, I'm trying to pick some keys, one nested (so path), but I need to keep the key of it like pick: https://goo.gl/ajdmKj
Is there a better way than this? https://goo.gl/TZ12Qc
Aaron Mc Adam
@aaronmcadam
Aug 01 2017 10:44
This is my latest: https://goo.gl/2VLUE9
matrixbot
@matrixbot
Aug 01 2017 11:09
Siilwyn Aaron Mc Adam (Gitter): createPayload2 looks good, it's point-free and simple. I would keep it.
Aaron Mc Adam
@aaronmcadam
Aug 01 2017 11:09
Thanks, I was trying to think if there was a better option than converge and merge
Selwyn
@Siilwyn
Aug 01 2017 14:15
@Yord still stuck on the same thing... Maybe I should write imperative first and if I have time left try to make it a bit functional. :thought_balloon:
I figured out that since my data has other keys too which I want the symmetricDifferenceWith to ignore R.equals is not enough. Can't come up with a solution though, closest I got is using a lensPath like this: https://goo.gl/hb3oTK
const getDifferences = pipe(
  (...args) => map(toPairs, args),
  // apply(symmetricDifferenceWith(equals)),
  apply(symmetricDifferenceWith(eqBy(scoreLens))),
  groupBy(head),
  map(chain(tail))
);
I can compare them by extracting the 's' property but then I lose all other data which I still want in the final result. :/
Syaiful Bahri
@syaiful6
Aug 01 2017 16:16
@Siilwyn the easiest way i think just merge the object directly using mergeWithKey, then filter out the one that empty.
Syaiful Bahri
@syaiful6
Aug 01 2017 16:24
or if you don't care about the key, use mergeWith
R.pickBy(
  R.compose(not, isEmpty),
  R.mergeWith(concatIf, sampleA, sampleB)
 )
Syaiful Bahri
@syaiful6
Aug 01 2017 16:30
where concatIf defined as const concatIf = R.ifElse(R.eqProps('s'), R.always([]), R.pair)
Aaron Mc Adam
@aaronmcadam
Aug 01 2017 16:44
Is there a simpler way to pluck keys from an object, one from the top level, and one nested? (https://goo.gl/QCG9Zy)
basically I'm wishing for a props function that can take a list within a list
props(['body', ['request', 'references']]) would solve this for me
or dot syntax, which I'm sure has been mulled over before
Brad Compton (he/him)
@Bradcomp
Aug 01 2017 17:16
@aaronmcadam Something like this: https://goo.gl/buxMvr :question: It isn't perfect, but it works. I don't think there is a built in for that, though applySpec might help too...
Aaron Mc Adam
@aaronmcadam
Aug 01 2017 17:18
I'm not sure if I can use applySpec because I don't know which keys I need ahead of time
Brad Compton (he/him)
@Bradcomp
Aug 01 2017 17:19
gotcha
Aaron Mc Adam
@aaronmcadam
Aug 01 2017 17:19
Thanks though, I think with yours, I'd need to merge the objects into one too
I didn't know about o
Brad Compton (he/him)
@Bradcomp
Aug 01 2017 17:21
Sorry, I should have looked at your example. I was going off the behavior of props
Aaron Mc Adam
@aaronmcadam
Aug 01 2017 17:21
ah yeah that's cool!
Brad Compton (he/him)
@Bradcomp
Aug 01 2017 17:22
Yeah, o is new. Could have just used compose, but less typing ;)
Aaron Mc Adam
@aaronmcadam
Aug 01 2017 17:22
I'm not really getting the difference between o and compose
Brad Compton (he/him)
@Bradcomp
Aug 01 2017 17:22
o is binary instead of variadic. It can also be curried
Aaron Mc Adam
@aaronmcadam
Aug 01 2017 17:23
it says it's unary in the docs?
oh sorry, it returns one
I'm trying to work out what's important about "the rightmost function passed to o will be invoked with only one argument."
Brad Compton (he/him)
@Bradcomp
Aug 01 2017 17:24
Aaron Mc Adam
@aaronmcadam
Aug 01 2017 17:25
is it just some sugar for a common composition case?
Brad Compton (he/him)
@Bradcomp
Aug 01 2017 17:25
Yeah, it's more ... composable ;)
So if you pass in a binary function as the last argument to compose, then the result will take two values, but with o, it will only take one value. Then you can pass that partially applied function to the next function
Aaron Mc Adam
@aaronmcadam
Aug 01 2017 17:29
hmm that helps but I'm still trying to work out why withA2 isn't taking the prop off the object and incrementing it
It's also after my work day here so maybe my brain is screwed :D
I know you're saying because prop is binary, compose is returning a binary function
but I think I've written something similar before.. maybe I had to curry it that time though
Brad Compton (he/him)
@Bradcomp
Aug 01 2017 17:43
R.compose
Brad Compton (he/him)
@Bradcomp
Aug 01 2017 17:43
Because compose isn't curried, it can't even use the placeholder
So it's trying to call R.__(prop('a', inc)) while R.__ is not a function
Aaron Mc Adam
@aaronmcadam
Aug 01 2017 18:32
ahhh thanks that helps a ton @Bradcomp :)
Cody Seibert
@codyseibert
Aug 01 2017 19:27

hey all, is there a method that I could use that is similar to this? (I call this Forking)

Array.prototype.fork = function(paths) {
  return paths.map(cb => cb(this));
}

which could be invoked like so:

[1, 2]
  .fork([
    a => a * a,
    a => a * a * a
  ]) // [[1, 4],[1, 8]]

basically it sends the same list to multiple functions

Bijoy Thomas
@bijoythomas
Aug 01 2017 19:42
converge?
Matthew Willhite
@miwillhite
Aug 01 2017 19:50
also lift…
liftN(2, 2arityFn)(1arityFn)(1arityFn)
Cody Seibert
@codyseibert
Aug 01 2017 19:59
cool
so I'm trying to more specifically do this
console.log(
  R.converge(
    R.concat, [
      t => [t[0] % 12],
      t => [t[0] < 12]
    ]
  )(
    R.map(parseInt, R.split(':', '18:23'))
  )
)
but I'm wondering if there is a way to write it like so, or if this breaks the whole aspect of "functional" code:
console.log(
  R
    .split(':', '18:23')
    .map(parseInt)
    .converge(R.concat, [
      t => [t[0] % 12],
      t => [t[0] < 12]
    ])
 )
I might just be too used to using lodash / javascript
Matthew Willhite
@miwillhite
Aug 01 2017 20:04
you could use pipe if you want that top-down feel:
pipe(
  split(‘:’),
  map(parseInt),
  converge(…)
)(’18:23’)
Cody Seibert
@codyseibert
Aug 01 2017 20:08
oh wow, awesome!
thanks!
Matthew Willhite
@miwillhite
Aug 01 2017 20:09
yay currying!
:sweat_smile:
Selwyn
@Siilwyn
Aug 01 2017 20:24
@syaiful6 thank you again! Will look into mergeWith!