I'm new to functional coding, and I've stumbled across following tutorial example:
const mathPipe = R.pipe( // 10
R.multiply(4), // 4 * 10
R.add(2), // 2 + 40
R.divide(2) // 2 / 42
);
mathPipe(10)
> 21
When I run this, it gives me 0.047619047619047616 which seems correct to me, since Ramda is function-first, data-second. I added the comments to show what in fact is calculated.
The tutorial however says the expected answer is 21, so the actual last operation would be 42 / 2.
So I guess my questions is: Was there a time when the argument order was inverted? Or is the tutorial just plainly incorrect? It is from July 2018.
I hope it's ok to ask this but I'm very new to functional coding and this was just a bit too confusing.
I assume you are talking about this article? The example is just wrong — the author knows what should happen, as he describes:
Thus, he would have known it is
R.divide(2)(current)(i.e.2/current) being evaluated; i.e. Ramda works exactly as the author explains it, both now and then. However the result shown in his example contradicts both his explanation, and the actual result.