-
Notifications
You must be signed in to change notification settings - Fork 670
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
add curried version of createSelector? #159
Comments
Hey Martin, Not sure if this is what you meant by a lot of boilerplate, but would this do it? const uncurry = curriedFn => (...args) => (
args.reduce((left, right) => left(right), curriedFn)
);
const createSelectorN = (...selectors, curriedFn) => (
createSelector(...selectors, uncurry(curriedFn))
); |
Hey @MattSPalmer, Thanks! That is indeed exactly what I wanted... Ugh. Maybe I should have slept about it first before creating an issue. I will write a helper file and import my Feel free to close this :) |
Actually, what if we could change the API of createSelector a bit to accept the selector functions first as an array of functions and let the second argument be the actual transforming function, where the second argument could also be applied at a later point in time, as the whole thing would be curried.
We would be more explicit with the functions we fed into our actual transforming function and could do a lot more stuff like, using |
It's an interesting proposal, but at this point in time the API for @MattSPalmer Nice solution, in case anyone else is wanting the same thing I'm going to link to it from the FAQ. Cheers! |
@ellbee Is it still something needed to release |
Not needed for 3.0.0, but lets keep it open. |
Can anyone provide an example how-to use createSelectorN? Thanks. |
A minor aside, and also incompatible: it might be useful to use partial application with
to
so a user may call
which of course is just a This can be useful when the same lifted
so it's just a minor DRY application but chimes well with currying the ordinary function |
Closing as this seems to be both stale and adequately answered. |
I've just ran into this problem. I wanted to cleanup some selectors and refactor them to be point-free.
Now, as the very last function of
createSelector
receives the return values of all the functions before that, I have to write one function that takes allx
arguments at once and handle them. this makes it kinda hard to write in point-free style.Given this selector for example:
to get rid of
(user, pets)
I could write (using ramda)and use that as the last function within my selector.
BUT, and here's the thing: Only when the function would apply each argument one by one like this:
favoritePetsOfUser(user)(pets)
so first call to
favoritePetsOfUser
would setup the path to the user and the second one would then call the actualfilter
method.But actually it will be called like this
favoritePetsOfUser(user, pets)
.To make it work now I'd have to uncurry my functions first, which would be a lot of boilerplate if this happens a lot.
This sucks, so I'd love to have a curried version of
createSelector
, likecreateSelectorN
or something like that, that applies each argument to the last function one by one.I hope this makes sense to you. It's 2 am here almost and I'm pretty tired 😎 👍
Thanks!
The text was updated successfully, but these errors were encountered: