[proposal] Object.pick

Jacob Pratt jhprattdev at gmail.com
Thu Jul 26 03:15:11 UTC 2018


Unsure if this is even still being actively weekend out, but I've played
around with the binding operator in Babel for this purpose. It definitely
has its use case; mine was filtering allowed keys for a REST API.

On Wed, Jul 25, 2018, 19:54 Mikkel Davis <mikkeld at gmail.com> wrote:

> Thanks for the heads up! As I mentioned above, I've seen it come up
> before, but all the top results when searching are syntactic proposals.
> Syntax would be cool and all, but like you said it may or may not be
> justified. In the mean time, I don't see any traction for an Object util
> proposal like this. Does anybody know if this specifically has come up
> before and if there is a big reason against it?
> ---
> Mikkel R. Davis
>
>
> On Wed, Jul 25, 2018 at 5:42 PM Isiah Meadows <isiahmeadows at gmail.com>
> wrote:
>
>> Just as a heads up, this has come up plenty of times before, both as a
>> function and (usually) syntax:
>> https://www.google.com/search?q=site%3Aesdiscuss.org+pick
>>
>> I'm good with it being a built-in function, but it's harder to justify
>> using syntax apart from an easier time building up the relevant type
>> ICs.
>> -----
>>
>> Isiah Meadows
>> me at isiahmeadows.com
>> www.isiahmeadows.com
>>
>>
>> On Wed, Jul 25, 2018 at 5:45 PM, Mikkel Davis <mikkeld at gmail.com> wrote:
>> > I've seen proposals for syntax additions that give functionality
>> similar to
>> > lodash's "pick" utility. But I think it may be more appropriate to add
>> it as
>> > an Object utility in the same vein of `Object.assign`, `Object.keys`,
>> > `Object.values`. After a quick search, I was surprised to not find an
>> > existing proposal like this. Why would that be?
>> >
>> > For me, this isn't just one of those "huh, that's a neat lodash util
>> that
>> > would be nifty to have natively." The codebase I work on most often
>> already
>> > has lodash everywhere, and I have found myself utilizing _.pick
>> frequently,
>> > e.g. mapping or passing down portions of React state or props. I really
>> > think is common enough that it justifies addition to the spec.
>> >
>> > ```js
>> > const person = {
>> >     first: 'Marie',
>> >     last: 'Curie',
>> >     age: 51,
>> >     address: 'Grenoble, France',
>> > };
>> >
>> > Object.pick(person, ['first', 'age']);  // {first: "Marie", age: 51}
>> > ```
>> >
>> > The only other concise way to do this I can think of, using latest ES is
>> > `(({first, age}) => ({first, age}))(person)`, which is quite
>> undesirable,
>> > for a variety of reasons.
>> >
>> > Another name that might be nice is `Object.slice`.
>> >
>> > ---
>> > Mikkel R. Davis
>> >
>> > _______________________________________________
>> > es-discuss mailing list
>> > es-discuss at mozilla.org
>> > https://mail.mozilla.org/listinfo/es-discuss
>> >
>>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180725/c5adabb4/attachment-0001.html>


More information about the es-discuss mailing list