These are chat archives for ramda/ramda

3rd
Feb 2017
Lewis
@6ewis
Feb 03 2017 03:36
hey guys quick question, in cases where R.merge and R.evolve do the same job, what would you prefer and why
Matthew Willhite
@miwillhite
Feb 03 2017 03:46
I use merge when I want to combine two objects and evolve when I want to perform transformations on an object. Do you have an example where they do the same thing?
Lewis
@6ewis
Feb 03 2017 03:58
@miwillhite never mind it's not important, I was overthinking
Matthew Willhite
@miwillhite
Feb 03 2017 03:58
:sweat_smile:
Lewis
@6ewis
Feb 03 2017 03:58
or maybe not
const state = {ages: [10], nickname: "Lewix"};
R.merge(state, {ages: [10,"ten"]});
R.evolve({ages: R.append("ten")}, state);
@miwillhite here you go, which one would favor in this instance?
Matthew Willhite
@miwillhite
Feb 03 2017 04:01
I suppose I’d prefer evolve because append(‘ten’) doesn’t have to know anything about the original value of ages except that it is appendable…
Lewis
@6ewis
Feb 03 2017 04:02
@miwillhite I see, good one. I wonder which one is more performant (though ramda is not about performance). Well, maybe it will be when I turn 11
Matthew Willhite
@miwillhite
Feb 03 2017 04:03
:sunglasses:
Lewis
@6ewis
Feb 03 2017 04:07
:)
Tomáš Konrády
@tommmyy
Feb 03 2017 11:43
Hi, is there a way to refactor code bellow to point-free?
const transition = (duration, timing, props) => R.compose(
    R.join(', '),
    R.map(
        (prop) => `${prop} ${duration}s ${timing}`
    )
)(props);
James Forbes
@JAForbes
Feb 03 2017 11:48

Yes, but I think it will be a lot less clear what's going on.

I'm thinking you could curryN(3) Array.from, then concat the 's' with a lensIndex, and join(' '). But it'd be pretty unreadable

thought for a start you could remove the props arguments entirely
Tomáš Konrády
@tommmyy
Feb 03 2017 11:51
Thank you, James, but I can't: https://goo.gl/wXLjWA
or don't know how .D
James Forbes
@JAForbes
Feb 03 2017 11:52
Try: transition('2', 'linear')(['height', 'opacity'])
Tomáš Konrády
@tommmyy
Feb 03 2017 11:52
yep that works
James Forbes
@JAForbes
Feb 03 2017 11:53

Then all we're really doing is appending a string to prop, then joining. So it might be better to generate the string separately.

const transition = format =>
  R.compose(
    R.join(', ')
    ,R.map( R.append( format ) )
  )

And at the point its probably easier to do it all inline?

props.map( R.append(' 2s linear') ).join(', ')
Tomáš Konrády
@tommmyy
Feb 03 2017 11:55
oh yeah, that's cool
Adam Szaraniec
@mimol91
Feb 03 2017 13:21
Hey.
Any hint how to do such transofrmation
const data = {
  '1' :{
    name: 'bob'
  },
  '2' :{
    name: 'bob2'
  }
}

const transformedData = [
  {
    name: 'bob',
    key: '1'
  },
  {
    name: 'bob2',
    key: '2'
  }
]
I can flat to array using values but no clue how add this key property
Matthew Willhite
@miwillhite
Feb 03 2017 13:38
@mimol91 Not the most clever solution, but it works:
R.compose(
  R.map(function (pair) {
    return R.merge(R.objOf('key', pair[0]), pair[1]);
  }),
  R.toPairs
)
(data);
Adam Szaraniec
@mimol91
Feb 03 2017 13:39
thanks
Kirill Rogovoy
@kirillrogovoy
Feb 03 2017 14:33
@mimol91 @miwillhite
I find this a bit more readable. Not point-free, but I'm not obsessed about it .:)
R.pipe(R.map((obj, key) => ({ key, name: obj.name })), R.values)(data)
Rick Medina
@rickmed
Feb 03 2017 22:15
any tips on removing one traverse and xs point?
const catDir = R.pipeK(
  ls,  // Task [str]
  R.traverse(Task.of, isFile),   // Task [str|bool]
  xs => R.traverse(Task.of, read, R.without([false])(xs))
)
Denis Stoyanov
@xgrommx
Feb 03 2017 22:34
@rickmed compose?
@rickmed
const catDir = R.pipeK(
  ls,  // Task [str]
  R.traverse(Task.of, isFile),   // Task [str|bool]
  R.compose(R.traverse(Task.of, read), R.without([false]))
)
η-conversion of lambda calculus
@rickmed also compose inside traverse
@rickmed try it
const catDir = R.pipeK(
  ls,  // Task [str]
  R.without([false]),
  R.traverse(Task.of, compose(isFile, read))
)
Rick Medina
@rickmed
Feb 03 2017 22:44
@xgrommx something like the last one but I need the without between the isFile and read