These are chat archives for ramda/ramda

5th
Jan 2017
Aaron Rice
@adrice727
Jan 05 2017 00:48

I'm having an issue with a curried function and I have no clue what I'm doing wrong. Here is the code:

    const createEmbed = R.curry(create)(null, apiKey, R.__, body.domains, body.layout);
    const buildResponse = data => Promise.resolve(R.assoc('id', data.embedId, R.pick(['embedId', 'fileUrl', 'domains'], data)));

    validatePost(body, headers)
      .then(R.partial(getApiSecret, [headers['x-my-auth']]))
      .then(createEmbed)
      .then(buildResponse)
      .then(resolve)
      .catch((error) => {
        reject(new APIError(error.message || error,
          error.status || httpStatus.FORBIDDEN,
          error.code || -1));
      });

When I log typeof createEmbed, the type is object and the function inside create which uses the third parameter is receiving { '@@functional/placeholder': true } instead of the string returned by getApiSecret

Aaron Rice
@adrice727
Jan 05 2017 01:13
(Post of Shame) I need to use curryN to use placeholders ^^^
hemanth.hm
@hemanth
Jan 05 2017 04:46
Convincing my friend why ramda is better than lodash she was asking if she could do https://lodash.com/docs#get and https://lodash.com/docs#set with nested path with ramda
http://goo.gl/mEifZk is the closest I could get to lodash.set
would you folks suggest lenses or maybe just assoc and assocPath ?
Hardy Jones
@joneshf
Jan 05 2017 05:24
Yeah, assoc and assocPath are as close to set as you're going to get, ignoring mutation.
You could use that as a jumping off point to discuss the benefits of lenses.
If she needs mutation, there's nothing in ramda for her (I don't think).
hemanth.hm
@hemanth
Jan 05 2017 08:27
@joneshf I have convinced her that mutation is bad, I am working on nested setters and getters.
looking for something like R.assocPath('a.b.c'.split('.')',response)
Hardy Jones
@joneshf
Jan 05 2017 09:22
If you're trying to emulate lodash's stringly-typed DSL, I think you're going to have to write your own.
hemanth.hm
@hemanth
Jan 05 2017 13:50
trying to get as close as possible
Tushar Mathur
@tusharmath
Jan 05 2017 18:44

const predicate = R.useWith(R.equals, [
  R.prop('q'),
  R.prop('id')
])
const findItem = R.converge(R.find, [
  predicate,
  R.prop('list')
])

const data = {
  list: [
    {id: 0, name: 'A'},
    {id: 1, name: 'B'},
    {id: 2, name: 'C'}
  ],
  q: 1
}
const out = findItem(data)
Facing a weird problem with ramda above. out contains a function in the end which instead of the item.

weird because changing the predicate to —

const predicate = x => R.useWith(R.equals, [
  R.prop('q'),
  R.prop('id')
])(x)

just works!

Brad Compton (he/him)
@Bradcomp
Jan 05 2017 18:47
Your initial predicate is a binary function, whereas the altered one is unary.
converge will set its arity to the maximum arity of the branching functions
so in the first case, it will take two parameters, but in the modified case you're forcing the function to be unary
@ram-bot

const predicate = curryN(1, R.useWith(R.equals, [
  R.prop('q'),
  R.prop('id')
]))
const findItem = R.converge(R.find, [
  predicate,
  R.prop('list')
])

const data = {
  list: [
    {id: 0, name: 'A'},
    {id: 1, name: 'B'},
    {id: 2, name: 'C'}
  ],
  q: 1
}
const out = findItem(data)
ram-bot
@ram-bot
Jan 05 2017 18:49
undefined
Brad Compton (he/him)
@Bradcomp
Jan 05 2017 18:50
well, that didn't work either
BUT, that's still the root of the behavior you are seeing
Tushar Mathur
@tusharmath
Jan 05 2017 19:16
I see.
How do i solve it though?
Tushar Mathur
@tusharmath
Jan 05 2017 19:26
@Bradcomp
Brad Compton (he/him)
@Bradcomp
Jan 05 2017 19:35
You mean other than the way you did above?
@ram-bot
const predicate =   nAry(1,R.useWith(R.equals, [
  R.prop('q'),
  R.prop('id')
]))
const findItem = R.converge(R.find, [
  predicate,
  R.prop('list')
])

const data = {
  list: [
    {id: 0, name: 'A'},
    {id: 1, name: 'B'},
    {id: 2, name: 'C'}
  ],
  q: 1
}
findItem(data)
ram-bot
@ram-bot
Jan 05 2017 19:38
{ id: 1, name: 'B' }
Brad Compton (he/him)
@Bradcomp
Jan 05 2017 19:39
That's basically the same as what you have, but using the nAry function to force tha arity of the predicate
Tushar Mathur
@tusharmath
Jan 05 2017 19:40
:thumbsup: thanks a ton!
Its very difficult to debug ramda code.
Ryan Zeigler
@rzeigler
Jan 05 2017 20:45
@tusharmath R.tap is your friend :-)
Matt Ross
@amsross
Jan 05 2017 21:48
unless the result from R.tap is being passed to a function with arity > 1