These are chat archives for ramda/ramda

Jan 2019
Pranab Gupta
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
Jan 11 08:41
@ben-eb Thanks :) makes sense. I’m all for fixed arity functions.
Rakesh Pai
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
Jan 11 10:19

@Pranab16 had to give it a spin:

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

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
Jan 11 11:33
Thanks @rakeshpai for your response
Rakesh Pai
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
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
Jan 11 15:47
actually some.string.with.dots: true
Brad Compton (he/him)
Jan 11 16:04
Do you mean like this?
const markProp = prop => assoc(prop, true, {});

Sorry, I guess the ram-bot isn't working
Johnny Hauser
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