These are chat archives for ramda/ramda

14th
Dec 2016
jxl118
@jxl118
Dec 14 2016 02:21
Just learning ramda and came across something very strange to me trying to find duplicate values in an array.
Why would adding a tap make the following methods behave differently?
``````const R = require('ramda');

const trace = R.tap( x => console.log(x) );

const firstLastIndexDifferent = R.curry( (list, value) => {
return R.not( R.equals( R.indexOf(value, list), R.lastIndexOf(value, list)));
});

const find         = R.converge( R.find, [ firstLastIndexDifferent, R.identity ]);
const findComposed = R.converge( R.find, [ R.compose(firstLastIndexDifferent ), R.identity ]);
const findTraced   = R.converge( R.find, [ R.compose(firstLastIndexDifferent, trace ), R.identity ]);

console.log('find:'+find([1,2,3,4,3])); //find:function (a0) { return fn.apply(this, arguments); }
console.log('findComposed:'+findComposed([1,2,3,4,3])); //findComposed:function (a0) { return fn.apply(this, arguments); }
console.log('findTraced:'+findTraced([1,2,3,4,3]));  //findTraced:3``````
Brad Compton (he/him)
@Bradcomp
Dec 14 2016 02:43
@jxl118 Not sure what the root cause is, but `curry` is your culprit. Adding the `trace` to the beginning forces `firstLastIndexDifferent` to be treated as a unary function. https://goo.gl/Elec0H
OH, I got it!!!
`converge` bases the number of arguments it expects on the max number accepted by any of the branching functions.
`curry` will maintain a Function.length of 2 for `firstLastIndexDifferent`
As a result, your `find` and `findComposed` functions are both curried to take 2 arguments
`R.converge`
jxl118
@jxl118
Dec 14 2016 17:28
@Bradcomp Thanks for the fix and explanation
Daniel Tsui
@sdtsui
Dec 14 2016 20:42
Quick question: I want to associate multiple props to an object. Besides (i) composing `assoc`, and (ii) using `merge` with a new object, what other operations do I have available to me?
Rob Halff
@rhalff
Dec 14 2016 21:42
this oughta work `export myFunc from './myFunc' using curry`
I guess babel doesn't prevent doing any of those things.
Kliment Mamykin
@kmamykin
Dec 14 2016 22:17
cant figure out how to group list by a predicate which is applied to adjasent elements in the list, e.g [0,1,2,3,1,2,0,4,5,6,9] -> [[0,1,2,3],[1,2],[0],[4,5,6],[9]] (with predicate (a,b) => a+1==b)
Kliment Mamykin
@kmamykin
Dec 14 2016 23:50
for ^^ created ramda/ramda#2012