Skip to content

add curried version of createSelector? #159

Closed
@mrtnbroder

Description

@mrtnbroder

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 all x arguments at once and handle them. this makes it kinda hard to write in point-free style.

Given this selector for example:

const favoritePetsOfUser = (user, pets) => pets.filter((pet) => pet.id === user.favorites.favoritePetId)
const petsOfUserSelector = createSelector(
  userSelector,
  petsSelector,
  favoritePetsOfUser
)

to get rid of (user, pets) I could write (using ramda)

const pathToFav = R.pathEq(['pets', 'favoritePetId'])

// and use it like this:
const favoritePetsOfUser = R.compose(R.filter, pathToFav)

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 actual filter 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, like createSelectorN 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!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions