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

New functions- omit, pick, pickOrDefault, pickBy #51

Open
singla-shivam opened this issue Jun 19, 2022 · 2 comments
Open

New functions- omit, pick, pickOrDefault, pickBy #51

singla-shivam opened this issue Jun 19, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@singla-shivam
Copy link
Member

Is your feature request related to a problem? Please describe.
NA

Describe the solution you'd like
Need to have some more functions. These functions operate on an object (functor) and return a new object.

  1. Omit- This function will take a list of keys (strings) and will return new object with those list of keys not included in the objects.
Fae.omit(['a', 'd'], { a: 1, b: 2, c: 3, d: 4 });  // { b: 2, c: 3 }
  1. Pick- This function will take a list of keys (strings) and will return new object with including those keys only which are in given list of keys.
Fae.pick(['a', 'd', 'e'], { a: 1, b: 2, c: 3, d: 4 }); // { a: 1, d: 4 }
  1. PickOrDefault- This function will take a list of keys (strings) and will return new object with including those keys only which are in given list of keys, and assign a value calculated by given default function if the corresponding key doesn't exist on the object.
Fae.pickOrDefault(['a', 'c'], (key: string) => key + '-default', { a: 1, b: 3 }) //  { a: 2, c: 'c-default' }
Fae.pickOrDefault(['a', 'c', 'd'], Fae.always(4), { a: 1, b: 3 }) //  { a: 2, c: 4, d: 4 }
  1. PickBy- This function will take a predicate function, and will return a new object including keys which satisfy the predicate function.
Fae.pickBy((key: string) => k.length >= 2, { a: 1, bc: 2, def: 3 }) // { bc: 2, def: 3 }

Additional context
Add any other context or screenshots about the feature request here.

@singla-shivam singla-shivam added the enhancement New feature or request label Jun 19, 2022
@neelra8n
Copy link
Member

assign me , and help me understand this issue

@singla-shivam
Copy link
Member Author

Sure @neelra8n

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

No branches or pull requests

2 participants