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

Support returning object partials from select #21

Open
evanrs opened this issue Apr 15, 2016 · 1 comment
Open

Support returning object partials from select #21

evanrs opened this issue Apr 15, 2016 · 1 comment

Comments

@evanrs
Copy link
Owner

evanrs commented Apr 15, 2016

Select, or some new method should support return object partials, like lodash pick.

@evanrs
Copy link
Owner Author

evanrs commented Apr 15, 2016

One implementation could be

    select(key, __, ...args) {
      return (
        // A list of arguments > 3 returns those values as an array        
        // args.length ?
        //   [key, __, ...args].map((arg) =>
        //     isArray(arg) ? selector(...arg) : selector(arg)) :

        // Two array of values to select and defaults
        isArray(key) && isArray(__) ?
          map(key, (key, idx) => selector(key, __[idx])) :

        // A object that is a mapping of `{ [key]: [default] }`
        isObject(key) ?
          mapValues(key, (__, key) => selector(key, __)) :

        // Default behavior
        selector(...arguments)
      )
    }

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

No branches or pull requests

1 participant