char0n / ramda-adjunct

Ramda Adjunct is the most popular and most comprehensive set of functional utilities for use with Ramda, providing a variety of useful, well tested functions with excellent documentation.
https://char0n.github.io/ramda-adjunct/
BSD 3-Clause "New" or "Revised" License
679 stars 85 forks source link

Psi combinator #634

Open guillaumearm opened 6 years ago

guillaumearm commented 6 years ago

Please see #250 and http://hackage.haskell.org/package/base-4.10.1.0/docs/Data-Function.html#v:on

implementation idea :

// Psi
const on = const psi = curry((f, g, x, y) => f(g(x))(g(y)));

// usage
RA.on(R.prop('type'), R.comparator(myComparator))
char0n commented 6 years ago

legitimate.

drupol commented 4 years ago

The Haskell implementation of On is const on = curry((f, g, x, y) => g(f(x), f(y)));.

However, I would not use the comma to separate the terms, I would rather write it this way:

const on = curry((f, g, x, y) => f(g(x))(g(y));

See a PHP implementation here.

char0n commented 4 years ago

Thanks for your comment. fantasy-land combinators defines psi combinator as following:

const psi = curry((f, g, x, y) => f(g(x))(g(y)));

It's almost the same as your suggested signature, but the order of execution of f and g is reversed. Any idea why that is?

drupol commented 4 years ago

You're right, my comment was wrong. I updated it.

The correct implementation is: const on = curry((f, g, x, y) => f(g(x))(g(y));