Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

on :: (b -> b -> c) -> (a -> b) -> a -> a -> c #281

Closed
Bradcomp opened this issue Nov 13, 2016 · 2 comments
Closed

on :: (b -> b -> c) -> (a -> b) -> a -> a -> c #281

Bradcomp opened this issue Nov 13, 2016 · 2 comments

Comments

@Bradcomp
Copy link
Member

While the general useWith and converge from Ramda aren't very well typed, I do find them to be useful functions. One of my main use cases for useWith is to emulate Haskell's on function (this is also known as the psi combinator).

Example:

//Point :: {x, y}
const x = prop('x');

//Point -> Point -> Number
const leftmost = on(min, x);
const rightmost = on(max, x); 

I struggle with the parameter order for this function. In Haskell it's typically used in infix form:

leftmost = min `on` x

As a result, I generally define it using the signature above, even though there could be an argument made that the opposite order makes just as much sense.

Is there enough interest for this to be part of Sanctuary?

@davidchambers
Copy link
Member

Is there enough interest for this to be part of Sanctuary?

This function seems useful to me. Would you like to submit a pull request?

I think the type signature you provided is missing one a ->, by the way.

@Bradcomp Bradcomp changed the title on :: (b -> b -> c) -> (a -> b) -> a -> c on :: (b -> b -> c) -> (a -> b) -> a -> a -> c Nov 13, 2016
@Bradcomp
Copy link
Member Author

Thanks! I was missing the a. I will work on a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants