These are chat archives for ramda/ramda

28th
Dec 2017
diqye
@diqye2014
Dec 28 2017 07:55
converge is easy to confuse . Compared to arrow function
Piero Maltese
@pierissimo
Dec 28 2017 10:37

morning guys.
That's a snipped that replace a 'node' in a list of 'nodes'.

const newNodes = R.update(
    R.findIndex(
        R.equals(nodeToReplace),
        nodes
    ),
    newNode,
    nodes
);

That, syntax is very long and there are some repetitions.
That one is slightly better:

const newNodes = R.compose(
    R.update(R.__, newNode, nodes),
    R.findIndex(R.__, nodes),
    R.equals(nodeToReplace)
)();

Any suggestion?

Nik
@niksosf
Dec 28 2017 19:15
Couldn't we nodes.map( x => x === oldNode ? newNode: x) ?
Are
@are1000
Dec 28 2017 19:28
Wouldn't indexOf and splice work tho? No need to walk through entire array.
nodes.splice(nodes.indexOf(oldNode), 1, newNode)