These are chat archives for ramda/ramda

16th
Sep 2016
Eugene Lerman
@airbugg
Sep 16 2016 09:03
@kwijibo Apologies for not commenting sooner, this is great! Thanks so much! :D
Nick Kenny
@uberteck
Sep 16 2016 14:10

Hi all, does anyone know what changed with intersectionWith between 0.19.0 and 0.22.1?

Not sure if it's a regression or expected behaviour...

It seems in 0.19 it used to matter which order you put in the two sets, which was useful to filter one set by the other.

I've linked to two REPLs with the difference below.

Now it just seems to only return results from the list with the lowest length. In the 0.22.1 example below swapping the order of one and two does nothing, but if you uncomment one extra line in one it behaves like it did in 0.19. If you then uncomment the fourth line it then always gives results from list one.

My assumption is that some optimisation has been done to perhaps loop through the shortest list. Is the new behaviour expected or is this a regression?

with_0_19_0

with_0_22_1

Keith Alexander
@kwijibo
Sep 16 2016 14:46
@airbugg It's not the most efficient solution, but glad it's of some interest. It might be clearer to not use the more tacit style, and more efficient to use a dictionary for filtering the edges:
const hashByProp = (prop, list) => list.reduce((result, item)=> R.assoc(item[prop], item, result), {})

const subGraphByNode = nodePredicate => ({nodes, edges}) => {
  const nodeSubset = nodes.filter(nodePredicate)
  const nodeHash = hashByProp('nodeId', nodeSubset)
  const edgesSubset = edges.filter(({sourceID, targetID}) => nodeHash[sourceID] || nodeHash[targetID])
  return {nodes: nodeSubset, edges: edgesSubset}
}
Kurt Milam
@kurtmilam
Sep 16 2016 15:04
@uberteck Have you taken a look at the upgrade guides for history on intersectionWith?
You may find this discussion enlightening and helpful: ramda/ramda#1868
Kurt Milam
@kurtmilam
Sep 16 2016 15:10
In short, it looks like a regression that is already known, and the core team members are working on a solution that may include deprecating intersectionWith.
You can find the upgrade guides (similar to changelogs) here: https://github.com/ramda/ramda/issues?q=label%3A%22upgrade+guide%22
Nick Kenny
@uberteck
Sep 16 2016 15:49
@kurtmilam Ah, thanks, the upgrade guides are exactly what I was trying to find. I'll keep my eye out for innerJoin in the next version ;)