These are chat archives for ramda/ramda

8th
Jan 2019
Johnny Hauser
@m59peacemaker
Jan 08 00:46
ack
I found that some of them depend on others
data is crazy and fun
Johnny Hauser
@m59peacemaker
Jan 08 00:52
What do you guys do when you take some data, transform it, but then need to transform some of it based on the transformation result so far AND the original data?
Johnny Hauser
@m59peacemaker
Jan 08 01:01
R.pipe(
    R.evolve({ Parameters: R.pipe(R.indexBy(R.prop('Parameter')), R.map(R.prop('Value'))) }),
    R.converge(merge, partialFormatters),
        // but now I need do something with the result of the first line and the result of the second line
)
Johnny Hauser
@m59peacemaker
Jan 08 01:27
maybe time to abandon point-free there?
const both lines and then I can get back to point free for the return value
Rocky Madden
@rockymadden
Jan 08 03:07
That or use a combinator, here.
P combinator?
Johnny Hauser
@m59peacemaker
Jan 08 03:16
hmm
That's a bit beyond my current understanding.
Oh, I see
I can't process how to do something like that in my scenario
Syaiful Bahri
@syaiful6
Jan 08 04:22
@m59peacemaker useWith seem good, R.useWith(functionArity2, [R.evolve({ Parameters: R.pipe(R.indexBy(R.prop('Parameter')), R.map(R.prop('Value'))) }), R.converge(merge, partialFormatters))
Johnny Hauser
@m59peacemaker
Jan 08 04:25
@syaiful6 interesting!
I had just come up with this finally:
R.pipe(
    R.evolve({ Parameters: R.pipe(R.indexBy(R.prop('Parameter')), R.map(R.prop('Value'))) }),
    R.converge
        (R.unapply(R.zipObj([ 'raw', 'formatted' ])))
        ([
            R.identity,
            R.converge (merge) (partialFormatters)
        ]),
    // do stuff with both here
    R.prop('formatted')
)
yours is better
Mattibun
@Mattibun
Jan 08 10:09
Hello everyone. New to Ramda and to a lot of functional programming. I've tried converting a part of my simulation code into Ramda and threw it up into jsfiddle. It seems to work, but are there things I could be doing better? https://jsfiddle.net/s6u95djL/18/
Alex Deas
@alex-deas_gitlab
Jan 08 10:13
@Mattibun most functions in ramda are already curried. So you shouldn’t need to declare isArr to handle one parameter but can just use is(Array)
Mattibun
@Mattibun
Jan 08 10:19
@alex-deas_gitlab, thanks! I get the concept of currying but finding where it can be applied and when to do it is still eluding me.
Rakesh Pai
@rakeshpai
Jan 08 12:39
@Mattibun This looks good. Couple of suggestions though:
In JS, just as .addEventListener(evt => handleEvent(evt)) and .addEventListener(handleEvent) are (mostly) equivalent, your line 15 can just be const startBattle = R.pipe(checkClean, prepareEnemy);. There's no need to accept an argument and pass it along. This can be done in several places in the code.
This is just JS, not ramda/currying/any such stuff.

What @alex-deas_gitlab was saying is:

// Array check
function isArr(x) {
  return R.is(Array, x);
};

can just be written as:

const isArray = R.is(Array);

This works because of currying. Since you've only provided one of the required arguments to R.is, it returns a function that accepts the remaining argument(s).

Mattibun
@Mattibun
Jan 08 12:44
@rakeshpai I'm updating my jsfiddle based on your suggestions. I'm having to change the order of my function declarations, though I'm not sure if it's a JS thing or a jsfiddle thing (e.g. ReferenceError: can't access lexical declaration `checkEnemyObject' before initialization). I'll pop up a new version once it's ready. Thanks for the suggestion. :)
Rakesh Pai
@rakeshpai
Jan 08 12:49
Yes, you'll need to make sure that stuff you're referencing is declared first.