Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reverse arguments order in curried function (ramda js)

I have a higher order function: let's say for simplicity

const divideLeftToRight = x => y => x/y;

I would like to have a function that performs the division but from 'right to left'. In other words, I need to have:

const divideRightToLeft = x => y => y/x;

I thought about doing:

const divideRightToLeft = R.curry((x,y) => divideLeftToRight(y)(x));

I am wondering if there is a more elegant way to do it

like image 787
tcoder01 Avatar asked Mar 10 '23 00:03

tcoder01


1 Answers

You are looking for the flip function:

const divideRightToLeft = R.flip(divideLeftToRight)
like image 107
Bergi Avatar answered May 23 '23 07:05

Bergi