These are chat archives for ramda/ramda

11th
Jan 2019
Pranab Gupta
@Pranab16
Jan 11 08:18
Hello everyone. New to Ramda and trying to convert below piece of code into Ramda but didn't get any success
const getTitle = (obj, language, field = 'title') => {
  if (!language) return _get(obj, field);

  return _get(obj, `translations.${language}.${field}`);
}
Riku Tiira
@rikutiira
Jan 11 08:41
@ben-eb Thanks :) makes sense. I’m all for fixed arity functions.
Rakesh Pai
@rakeshpai
Jan 11 10:09
@Pranab16 That's a tricky one. Imperative code might be more readable than composed code. That said, I'd start with making obj the last argument for both _get (maybe by flipping it), and for getTitle. That'll help make it point-free.
Rakesh Pai
@rakeshpai
Jan 11 10:19

@Pranab16 had to give it a spin:

const getTitle = pipe(
  (language, field = 'title') => !language ? field : `translations.${language}.${field}`,
  flip(_get)
);

Not happy with it, though. Depending on how you plan to use it, you might consider the invocation weird (getTitle(language, field)(obj)).

Pranab Gupta
@Pranab16
Jan 11 11:33
Thanks @rakeshpai for your response
Rakesh Pai
@rakeshpai
Jan 11 11:41
No problem. Here's some more golfing:
const getPath = (language, field = 'title') =>
  language ? `translations.${language}.${field}` : field;

const getTitle = pipe( getPath, flip(_get) );
Adrian Skierniewski
@AdrianSkierniewski
Jan 11 15:32
Does ramda have any function that could easily transform some.string.with.dots to {some: { string: { with: { dots: true } } }?
Adrian Skierniewski
@AdrianSkierniewski
Jan 11 15:47
actually some.string.with.dots: true
Brad Compton (he/him)
@Bradcomp
Jan 11 16:04
Do you mean like this?
@ram-bot
const markProp = prop => assoc(prop, true, {});

markProp('some.string.here')
Sorry, I guess the ram-bot isn't working
Johnny Hauser
@m59peacemaker
Jan 11 20:41
Is this redundant some kind of way?
const concatPrices = R.converge(R.concat, [ R.prop('MyPricing'), R.prop('StandardPricing') ])
R.converge(R.assoc('prices'), [ concatPrices, R.identity ])
Sometimes I end up using identity in a place because I'm doing something needless
object comes in
concat its two props together
put that concatted value on the object at the given key