[Proposal] Optional spreading
Since you can do this now with:
[
1,
...(condition ? [2, 3] : []),
3,
]
and object spreading already handles this for you, is extra syntax really needed?
Since you can do this now with: ```js [ 1, ...(condition ? [2, 3] : []), 3, ] ``` and object spreading already handles this for you, is extra syntax really needed? On Thu, Aug 22, 2019 at 6:52 PM Scott Rudiger <scottrudiger at gmail.com> wrote: > I like it; code seems cleaner to me with its use. However, since the > syntax is so similar to optional chaining, it's too bad your goal with this > sample is to check for falsey values rather than nullish values. > > [ 1, ?...(condition && [2, 3]), // no extras:) 3, ] > > On Thu, Aug 22, 2019, 6:01 PM Beknar Askarov <beknaraskarov at gmail.com> > wrote: > >> Problem >> >> Spreading is great! It contributes towards "declerativity" of the >> language and reduces verbosity. I see one more feature to add to improve it. >> >> Consider following >> >> [ >> 1, >> condition && 2, >> condition && 3, >> 4, >> ].filter(Boolean) // filtering needed to remove falsy values >> // Results in >> [1, 2, 3, 4] // if condition is `truthy`// and >> [1, 4] // if not truthy. >> >> Another way to achieve the same result without the need of filtering after >> >> [ >> 1, >> ...(condition ? [2, 3] : []), // note extra [] in the end, to avoid errors >> 4, >> ] >> >> Similar pattern with objects >> >> { >> ...(condition ? { foo: 'bar' } : {}), // extra {} >> } >> >> Another pattern is when condition is the object itself, when it is known >> that type is one or falsy >> >> [ >> item1, >> item2, >> ...(itemsOrNull || []) // extra [] >> ] >> >> Similar for objects >> >> { >> ...(obj || {}), // extra {} >> } >> >> I see these patterns appearing very often. And these are cleanest >> examples I have seen so far. >> ProposalOptional spreadingWith condition >> >> // Arrays >> [ >> 1, >> ?...(condition && [2, 3]), // no extras:) >> 3, >> ]// Objects >> { >> ?...(condition && { foo: 'bar' }) // no extras:) >> } >> >> When condition is the object >> >> [ >> item1, >> item2, >> ?...itemsOrNull // no extras at all:) even (...) >> ] >> >> These look nicer and can be good for performance since (?...), since no >> cleanup is needed after to remove falsy values or extra spreading even when >> it is not needed. >> >> Looks intuitive (since: >> https://github.com/tc39/proposal-optional-chaining) >> Plays nice with typeings. >> >> What do you think? https://es.discourse.group/t/optional-spreading/93 >> _______________________________________________ >> 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/20190822/2c205384/attachment.html>
Indeed. I see your point.
But it really needs to be falsy check. Since falsy values are not "spreadable"
Indeed. I see your point. But it really needs to be falsy check. Since falsy values are not "spreadable" On Fri, 23 Aug 2019, 03:52 Scott Rudiger, <scottrudiger at gmail.com> wrote: > I like it; code seems cleaner to me with its use. However, since the > syntax is so similar to optional chaining, it's too bad your goal with this > sample is to check for falsey values rather than nullish values. > > [ 1, ?...(condition && [2, 3]), // no extras:) 3, ] > > On Thu, Aug 22, 2019, 6:01 PM Beknar Askarov <beknaraskarov at gmail.com> > wrote: > >> Problem >> >> Spreading is great! It contributes towards "declerativity" of the >> language and reduces verbosity. I see one more feature to add to improve it. >> >> Consider following >> >> [ >> 1, >> condition && 2, >> condition && 3, >> 4, >> ].filter(Boolean) // filtering needed to remove falsy values >> // Results in >> [1, 2, 3, 4] // if condition is `truthy`// and >> [1, 4] // if not truthy. >> >> Another way to achieve the same result without the need of filtering after >> >> [ >> 1, >> ...(condition ? [2, 3] : []), // note extra [] in the end, to avoid errors >> 4, >> ] >> >> Similar pattern with objects >> >> { >> ...(condition ? { foo: 'bar' } : {}), // extra {} >> } >> >> Another pattern is when condition is the object itself, when it is known >> that type is one or falsy >> >> [ >> item1, >> item2, >> ...(itemsOrNull || []) // extra [] >> ] >> >> Similar for objects >> >> { >> ...(obj || {}), // extra {} >> } >> >> I see these patterns appearing very often. And these are cleanest >> examples I have seen so far. >> ProposalOptional spreadingWith condition >> >> // Arrays >> [ >> 1, >> ?...(condition && [2, 3]), // no extras:) >> 3, >> ]// Objects >> { >> ?...(condition && { foo: 'bar' }) // no extras:) >> } >> >> When condition is the object >> >> [ >> item1, >> item2, >> ?...itemsOrNull // no extras at all:) even (...) >> ] >> >> These look nicer and can be good for performance since (?...), since no >> cleanup is needed after to remove falsy values or extra spreading even when >> it is not needed. >> >> Looks intuitive (since: >> https://github.com/tc39/proposal-optional-chaining) >> Plays nice with typeings. >> >> What do you think? https://es.discourse.group/t/optional-spreading/93 >> _______________________________________________ >> 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/20190823/70ac19d7/attachment-0001.html>
@Scott My mistake empty string [...""] is spreadable. But not sure if it is desirable behavior.
@Scott My mistake empty string [...""] is spreadable. But not sure if it is desirable behavior. On Fri, 23 Aug 2019, 04:42 Beknar Askarov, <beknaraskarov at gmail.com> wrote: > Indeed. I see your point. > > But it really needs to be falsy check. > Since falsy values are not "spreadable" > > > > On Fri, 23 Aug 2019, 03:52 Scott Rudiger, <scottrudiger at gmail.com> wrote: > >> I like it; code seems cleaner to me with its use. However, since the >> syntax is so similar to optional chaining, it's too bad your goal with this >> sample is to check for falsey values rather than nullish values. >> >> [ 1, ?...(condition && [2, 3]), // no extras:) 3, ] >> >> On Thu, Aug 22, 2019, 6:01 PM Beknar Askarov <beknaraskarov at gmail.com> >> wrote: >> >>> Problem >>> >>> Spreading is great! It contributes towards "declerativity" of the >>> language and reduces verbosity. I see one more feature to add to improve it. >>> >>> Consider following >>> >>> [ >>> 1, >>> condition && 2, >>> condition && 3, >>> 4, >>> ].filter(Boolean) // filtering needed to remove falsy values >>> // Results in >>> [1, 2, 3, 4] // if condition is `truthy`// and >>> [1, 4] // if not truthy. >>> >>> Another way to achieve the same result without the need of filtering >>> after >>> >>> [ >>> 1, >>> ...(condition ? [2, 3] : []), // note extra [] in the end, to avoid errors >>> 4, >>> ] >>> >>> Similar pattern with objects >>> >>> { >>> ...(condition ? { foo: 'bar' } : {}), // extra {} >>> } >>> >>> Another pattern is when condition is the object itself, when it is >>> known that type is one or falsy >>> >>> [ >>> item1, >>> item2, >>> ...(itemsOrNull || []) // extra [] >>> ] >>> >>> Similar for objects >>> >>> { >>> ...(obj || {}), // extra {} >>> } >>> >>> I see these patterns appearing very often. And these are cleanest >>> examples I have seen so far. >>> ProposalOptional spreadingWith condition >>> >>> // Arrays >>> [ >>> 1, >>> ?...(condition && [2, 3]), // no extras:) >>> 3, >>> ]// Objects >>> { >>> ?...(condition && { foo: 'bar' }) // no extras:) >>> } >>> >>> When condition is the object >>> >>> [ >>> item1, >>> item2, >>> ?...itemsOrNull // no extras at all:) even (...) >>> ] >>> >>> These look nicer and can be good for performance since (?...), since no >>> cleanup is needed after to remove falsy values or extra spreading even when >>> it is not needed. >>> >>> Looks intuitive (since: >>> https://github.com/tc39/proposal-optional-chaining) >>> Plays nice with typeings. >>> >>> What do you think? https://es.discourse.group/t/optional-spreading/93 >>> _______________________________________________ >>> 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/20190823/537bd77e/attachment-0001.html>
And it does result in empty array
[...''] -> []
So not much difference even if it passes through. Everything else would result in error if check was only nullish
And it does result in empty array [...''] -> [] So not much difference even if it passes through. Everything else would result in error if check was only nullish On Fri, 23 Aug 2019, 04:55 Beknar Askarov, <beknaraskarov at gmail.com> wrote: > @Scott My mistake empty string [...""] is spreadable. > But not sure if it is desirable behavior. > > > On Fri, 23 Aug 2019, 04:42 Beknar Askarov, <beknaraskarov at gmail.com> > wrote: > >> Indeed. I see your point. >> >> But it really needs to be falsy check. >> Since falsy values are not "spreadable" >> >> >> >> On Fri, 23 Aug 2019, 03:52 Scott Rudiger, <scottrudiger at gmail.com> wrote: >> >>> I like it; code seems cleaner to me with its use. However, since the >>> syntax is so similar to optional chaining, it's too bad your goal with this >>> sample is to check for falsey values rather than nullish values. >>> >>> [ 1, ?...(condition && [2, 3]), // no extras:) 3, ] >>> >>> On Thu, Aug 22, 2019, 6:01 PM Beknar Askarov <beknaraskarov at gmail.com> >>> wrote: >>> >>>> Problem >>>> >>>> Spreading is great! It contributes towards "declerativity" of the >>>> language and reduces verbosity. I see one more feature to add to improve it. >>>> >>>> Consider following >>>> >>>> [ >>>> 1, >>>> condition && 2, >>>> condition && 3, >>>> 4, >>>> ].filter(Boolean) // filtering needed to remove falsy values >>>> // Results in >>>> [1, 2, 3, 4] // if condition is `truthy`// and >>>> [1, 4] // if not truthy. >>>> >>>> Another way to achieve the same result without the need of filtering >>>> after >>>> >>>> [ >>>> 1, >>>> ...(condition ? [2, 3] : []), // note extra [] in the end, to avoid errors >>>> 4, >>>> ] >>>> >>>> Similar pattern with objects >>>> >>>> { >>>> ...(condition ? { foo: 'bar' } : {}), // extra {} >>>> } >>>> >>>> Another pattern is when condition is the object itself, when it is >>>> known that type is one or falsy >>>> >>>> [ >>>> item1, >>>> item2, >>>> ...(itemsOrNull || []) // extra [] >>>> ] >>>> >>>> Similar for objects >>>> >>>> { >>>> ...(obj || {}), // extra {} >>>> } >>>> >>>> I see these patterns appearing very often. And these are cleanest >>>> examples I have seen so far. >>>> ProposalOptional spreadingWith condition >>>> >>>> // Arrays >>>> [ >>>> 1, >>>> ?...(condition && [2, 3]), // no extras:) >>>> 3, >>>> ]// Objects >>>> { >>>> ?...(condition && { foo: 'bar' }) // no extras:) >>>> } >>>> >>>> When condition is the object >>>> >>>> [ >>>> item1, >>>> item2, >>>> ?...itemsOrNull // no extras at all:) even (...) >>>> ] >>>> >>>> These look nicer and can be good for performance since (?...), since >>>> no cleanup is needed after to remove falsy values or extra spreading even >>>> when it is not needed. >>>> >>>> Looks intuitive (since: >>>> https://github.com/tc39/proposal-optional-chaining) >>>> Plays nice with typeings. >>>> >>>> What do you think? https://es.discourse.group/t/optional-spreading/93 >>>> _______________________________________________ >>>> 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/20190823/0b4e2820/attachment-0001.html>
Like others said, this idea is good, but I think we can already achieve something decent and succinct enough
arrays:
// group by name, and accumulate data:
arr.reduce((m, {name, data, ...o}) => m.set(name, {...o, data:
[...m.get(name)?..data||[], ...data]}), new Map())
objects: {foo: 1, ...cond && {bar: 2}, qux: 3}
gist.github.com/caub/7494b4391c2d62c49b565d2cfc2c0c1f#file
Like others said, this idea is good, but I think we can already achieve something decent and succinct enough arrays: ```js // group by name, and accumulate data: arr.reduce((m, {name, data, ...o}) => m.set(name, {...o, data: [...m.get(name)?..data||[], ...data]}), new Map()) ``` objects: `{foo: 1, ...cond && {bar: 2}, qux: 3}` https://gist.github.com/caub/7494b4391c2d62c49b565d2cfc2c0c1f#file-fetch-wrapper-js-L11 On Fri, Aug 23, 2019 at 5:01 AM Beknar Askarov <beknaraskarov at gmail.com> wrote: > And it does result in empty array > > [...''] -> [] > > So not much difference even if it passes through. Everything else would > result in error if check was only nullish > > On Fri, 23 Aug 2019, 04:55 Beknar Askarov, <beknaraskarov at gmail.com> > wrote: > >> @Scott My mistake empty string [...""] is spreadable. >> But not sure if it is desirable behavior. >> >> >> On Fri, 23 Aug 2019, 04:42 Beknar Askarov, <beknaraskarov at gmail.com> >> wrote: >> >>> Indeed. I see your point. >>> >>> But it really needs to be falsy check. >>> Since falsy values are not "spreadable" >>> >>> >>> >>> On Fri, 23 Aug 2019, 03:52 Scott Rudiger, <scottrudiger at gmail.com> >>> wrote: >>> >>>> I like it; code seems cleaner to me with its use. However, since the >>>> syntax is so similar to optional chaining, it's too bad your goal with this >>>> sample is to check for falsey values rather than nullish values. >>>> >>>> [ 1, ?...(condition && [2, 3]), // no extras:) 3, ] >>>> >>>> On Thu, Aug 22, 2019, 6:01 PM Beknar Askarov <beknaraskarov at gmail.com> >>>> wrote: >>>> >>>>> Problem >>>>> >>>>> Spreading is great! It contributes towards "declerativity" of the >>>>> language and reduces verbosity. I see one more feature to add to improve it. >>>>> >>>>> Consider following >>>>> >>>>> [ >>>>> 1, >>>>> condition && 2, >>>>> condition && 3, >>>>> 4, >>>>> ].filter(Boolean) // filtering needed to remove falsy values >>>>> // Results in >>>>> [1, 2, 3, 4] // if condition is `truthy`// and >>>>> [1, 4] // if not truthy. >>>>> >>>>> Another way to achieve the same result without the need of filtering >>>>> after >>>>> >>>>> [ >>>>> 1, >>>>> ...(condition ? [2, 3] : []), // note extra [] in the end, to avoid errors >>>>> 4, >>>>> ] >>>>> >>>>> Similar pattern with objects >>>>> >>>>> { >>>>> ...(condition ? { foo: 'bar' } : {}), // extra {} >>>>> } >>>>> >>>>> Another pattern is when condition is the object itself, when it is >>>>> known that type is one or falsy >>>>> >>>>> [ >>>>> item1, >>>>> item2, >>>>> ...(itemsOrNull || []) // extra [] >>>>> ] >>>>> >>>>> Similar for objects >>>>> >>>>> { >>>>> ...(obj || {}), // extra {} >>>>> } >>>>> >>>>> I see these patterns appearing very often. And these are cleanest >>>>> examples I have seen so far. >>>>> ProposalOptional spreadingWith condition >>>>> >>>>> // Arrays >>>>> [ >>>>> 1, >>>>> ?...(condition && [2, 3]), // no extras:) >>>>> 3, >>>>> ]// Objects >>>>> { >>>>> ?...(condition && { foo: 'bar' }) // no extras:) >>>>> } >>>>> >>>>> When condition is the object >>>>> >>>>> [ >>>>> item1, >>>>> item2, >>>>> ?...itemsOrNull // no extras at all:) even (...) >>>>> ] >>>>> >>>>> These look nicer and can be good for performance since (?...), since >>>>> no cleanup is needed after to remove falsy values or extra spreading even >>>>> when it is not needed. >>>>> >>>>> Looks intuitive (since: >>>>> https://github.com/tc39/proposal-optional-chaining) >>>>> Plays nice with typeings. >>>>> >>>>> What do you think? https://es.discourse.group/t/optional-spreading/93 >>>>> >>>>> _______________________________________________ >>>>> 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/20190823/f79de205/attachment-0001.html>
@Scott Rudiger After thinking more about it. I would not like to conflict with semantics of optional chaining and null coalescing operator. So in order to not confuse people, maybe introduce two types of optional spread operators
-
?...
- Do not spread if nullish. Note nullish. Else try to spread. Signature Array: [?...(nullish | Iterable)]; Signature Object: {?...(nullish | object)}; -
!...
- Do not spread if false. Note FALSE not falsy. Else try to spread. Signature Array: [!...(false | Iterable)]; Signature Object: {!...(false | object)};
I think this can be an option to avoid consfusion
Why not !...
to check for all falsy and do not spread of falsy?
To avoid confusion and make developers to know their types
For example:
[!...(0 ?? [1 , 2])]; // throws TypeError. number 0 is not iterable
So better will be to use:
[!...(!!0 ?? [1 , 2])];
// OR
[?...(0 ?? [1 , 2])];
What do you think?
@Scott Rudiger After thinking more about it. I would not like to conflict with semantics of optional chaining and null coalescing operator. So in order to not confuse people, maybe introduce two types of optional spread operators 1. `?...` - Do not spread if nullish. Note nullish. Else try to spread. Signature Array: [?...(nullish | Iterable)]; Signature Object: {?...(nullish | object)}; 2. `!...` - Do not spread if false. Note FALSE not falsy. Else try to spread. Signature Array: [!...(false | Iterable)]; Signature Object: {!...(false | object)}; I think this can be an option to avoid consfusion Why not `!...` to check for all falsy and do not spread of falsy? To avoid confusion and make developers to know their types For example: ```js [!...(0 ?? [1 , 2])]; // throws TypeError. number 0 is not iterable ``` So better will be to use: ```js [!...(!!0 ?? [1 , 2])]; // OR [?...(0 ?? [1 , 2])]; ``` What do you think? On Fri, Aug 23, 2019 at 5:00 AM Beknar Askarov <beknaraskarov at gmail.com> wrote: > And it does result in empty array > > [...''] -> [] > > So not much difference even if it passes through. Everything else would > result in error if check was only nullish > > On Fri, 23 Aug 2019, 04:55 Beknar Askarov, <beknaraskarov at gmail.com> > wrote: > >> @Scott My mistake empty string [...""] is spreadable. >> But not sure if it is desirable behavior. >> >> >> On Fri, 23 Aug 2019, 04:42 Beknar Askarov, <beknaraskarov at gmail.com> >> wrote: >> >>> Indeed. I see your point. >>> >>> But it really needs to be falsy check. >>> Since falsy values are not "spreadable" >>> >>> >>> >>> On Fri, 23 Aug 2019, 03:52 Scott Rudiger, <scottrudiger at gmail.com> >>> wrote: >>> >>>> I like it; code seems cleaner to me with its use. However, since the >>>> syntax is so similar to optional chaining, it's too bad your goal with this >>>> sample is to check for falsey values rather than nullish values. >>>> >>>> [ 1, ?...(condition && [2, 3]), // no extras:) 3, ] >>>> >>>> On Thu, Aug 22, 2019, 6:01 PM Beknar Askarov <beknaraskarov at gmail.com> >>>> wrote: >>>> >>>>> Problem >>>>> >>>>> Spreading is great! It contributes towards "declerativity" of the >>>>> language and reduces verbosity. I see one more feature to add to improve it. >>>>> >>>>> Consider following >>>>> >>>>> [ >>>>> 1, >>>>> condition && 2, >>>>> condition && 3, >>>>> 4, >>>>> ].filter(Boolean) // filtering needed to remove falsy values >>>>> // Results in >>>>> [1, 2, 3, 4] // if condition is `truthy`// and >>>>> [1, 4] // if not truthy. >>>>> >>>>> Another way to achieve the same result without the need of filtering >>>>> after >>>>> >>>>> [ >>>>> 1, >>>>> ...(condition ? [2, 3] : []), // note extra [] in the end, to avoid errors >>>>> 4, >>>>> ] >>>>> >>>>> Similar pattern with objects >>>>> >>>>> { >>>>> ...(condition ? { foo: 'bar' } : {}), // extra {} >>>>> } >>>>> >>>>> Another pattern is when condition is the object itself, when it is >>>>> known that type is one or falsy >>>>> >>>>> [ >>>>> item1, >>>>> item2, >>>>> ...(itemsOrNull || []) // extra [] >>>>> ] >>>>> >>>>> Similar for objects >>>>> >>>>> { >>>>> ...(obj || {}), // extra {} >>>>> } >>>>> >>>>> I see these patterns appearing very often. And these are cleanest >>>>> examples I have seen so far. >>>>> ProposalOptional spreadingWith condition >>>>> >>>>> // Arrays >>>>> [ >>>>> 1, >>>>> ?...(condition && [2, 3]), // no extras:) >>>>> 3, >>>>> ]// Objects >>>>> { >>>>> ?...(condition && { foo: 'bar' }) // no extras:) >>>>> } >>>>> >>>>> When condition is the object >>>>> >>>>> [ >>>>> item1, >>>>> item2, >>>>> ?...itemsOrNull // no extras at all:) even (...) >>>>> ] >>>>> >>>>> These look nicer and can be good for performance since (?...), since >>>>> no cleanup is needed after to remove falsy values or extra spreading even >>>>> when it is not needed. >>>>> >>>>> Looks intuitive (since: >>>>> https://github.com/tc39/proposal-optional-chaining) >>>>> Plays nice with typeings. >>>>> >>>>> What do you think? https://es.discourse.group/t/optional-spreading/93 >>>>> >>>>> _______________________________________________ >>>>> 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/20190823/b911010b/attachment-0001.html>
On 23. 8. 2019 16:24, Beknar Askarov wrote:
@Scott Rudiger After thinking more about it. I would not like to conflict with semantics of optional chaining and null coalescing operator. So in order to not confuse people, maybe introduce two types of optional spread operators
?...
- Do not spread if nullish. Note nullish. Else try to spread. Signature Array: [?...(nullish | Iterable)]; Signature Object: {?...(nullish | object)};
!...
- Do not spread if false. Note FALSE not falsy. Else try to spread.
I read
!...foo
as
!(...foo)
that is, logical not. I'd tip it already works that way. In which case no go, break compat.
Herby
Signature Array: [!...(false | Iterable)]; Signature Object: {!...(false | object)};
I think this can be an option to avoid consfusion
Or add a new one. :-(
On 23. 8. 2019 16:24, Beknar Askarov wrote: > @Scott Rudiger After thinking more about it. > I would not like to conflict with semantics of optional chaining and > null coalescing operator. > So in order to not confuse people, maybe introduce two types of optional > spread operators > > > 1. `?...` - Do not spread if nullish. Note nullish. Else try to spread. > Signature Array: [?...(nullish | Iterable)]; > Signature Object: {?...(nullish | object)}; > > 2. `!...` - Do not spread if false. Note FALSE not falsy. Else try to > spread. I read !...foo as !(...foo) that is, logical not. I'd tip it already works that way. In which case no go, break compat. Herby > Signature Array: [!...(false | Iterable)]; > Signature Object: {!...(false | object)}; > > I think this can be an option to avoid consfusion Or add a new one. :-(
Thank you, everyone, for feedback. Sorry for not getting back for a while. I had some time to think and concluded that nullish noop in spreading is a good feature to be added to the language without complicating it too much. So please take a look at the explainer gist.github.com/askbeka/8bb17508ec250a789ea9bff683a50e38 and lets
discuss in es-discourse proposal es.discourse.group/t/optional-spreading-proposal/224, if you have
further feedback, please share
Thank you, everyone, for feedback. Sorry for not getting back for a while. I had some time to think and concluded that nullish noop in spreading is a good feature to be added to the language without complicating it too much. So please take a look at the explainer <https://gist.github.com/askbeka/8bb17508ec250a789ea9bff683a50e38> and lets discuss in es-discourse proposal <https://es.discourse.group/t/optional-spreading-proposal/224>, if you have further feedback, please share On Fri, Aug 23, 2019 at 7:18 PM Herby Vojčík <herby at mailbox.sk> wrote: > On 23. 8. 2019 16:24, Beknar Askarov wrote: > > @Scott Rudiger After thinking more about it. > > I would not like to conflict with semantics of optional chaining and > > null coalescing operator. > > So in order to not confuse people, maybe introduce two types of optional > > spread operators > > > > > > 1. `?...` - Do not spread if nullish. Note nullish. Else try to spread. > > Signature Array: [?...(nullish | Iterable)]; > > Signature Object: {?...(nullish | object)}; > > > > 2. `!...` - Do not spread if false. Note FALSE not falsy. Else try to > > spread. > > I read > > !...foo > > as > > !(...foo) > > that is, logical not. I'd tip it already works that way. In which case > no go, break compat. > > Herby > > > Signature Array: [!...(false | Iterable)]; > > Signature Object: {!...(false | object)}; > > > > I think this can be an option to avoid consfusion > > Or add a new one. :-( > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20200215/3c2a9328/attachment.html>
Since object spread already ignores nullish values, a syntax change would only be needed for array spread. Then, the two kinds of spread would support different syntactic features, which seems inconsistent.
Since object spread already ignores nullish values, a syntax change would only be needed for array spread. Then, the two kinds of spread would support different syntactic features, which seems inconsistent. On Sat, Feb 15, 2020 at 7:56 AM Beknar Askarov <beknaraskarov at gmail.com> wrote: > Thank you, everyone, for feedback. Sorry for not getting back for a while. > I had some time to think and concluded that nullish noop in spreading is a > good feature to be added to the language without complicating it too much. > So please take a look at the explainer > <https://gist.github.com/askbeka/8bb17508ec250a789ea9bff683a50e38> and > lets discuss in es-discourse proposal > <https://es.discourse.group/t/optional-spreading-proposal/224>, if you > have further feedback, please share > > On Fri, Aug 23, 2019 at 7:18 PM Herby Vojčík <herby at mailbox.sk> wrote: > >> On 23. 8. 2019 16:24, Beknar Askarov wrote: >> > @Scott Rudiger After thinking more about it. >> > I would not like to conflict with semantics of optional chaining and >> > null coalescing operator. >> > So in order to not confuse people, maybe introduce two types of >> optional >> > spread operators >> > >> > >> > 1. `?...` - Do not spread if nullish. Note nullish. Else try to spread. >> > Signature Array: [?...(nullish | Iterable)]; >> > Signature Object: {?...(nullish | object)}; >> > >> > 2. `!...` - Do not spread if false. Note FALSE not falsy. Else try to >> > spread. >> >> I read >> >> !...foo >> >> as >> >> !(...foo) >> >> that is, logical not. I'd tip it already works that way. In which case >> no go, break compat. >> >> Herby >> >> > Signature Array: [!...(false | Iterable)]; >> > Signature Object: {!...(false | object)}; >> > >> > I think this can be an option to avoid consfusion >> >> Or add a new one. :-( >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20200215/cc25de02/attachment.html>
Wouldn't simply making array spreading ignore nullish values be backward compatible? Unless one imagines that people are depending on this being an error somehow.
Wouldn't simply making array spreading ignore nullish values be backward compatible? Unless one imagines that people are depending on this being an error somehow. On Sat, Feb 15, 2020 at 10:05 AM Jordan Harband <ljharb at gmail.com> wrote: > Since object spread already ignores nullish values, a syntax change would > only be needed for array spread. Then, the two kinds of spread would > support different syntactic features, which seems inconsistent. > > On Sat, Feb 15, 2020 at 7:56 AM Beknar Askarov <beknaraskarov at gmail.com> > wrote: > >> Thank you, everyone, for feedback. Sorry for not getting back for a >> while. I had some time to think and concluded that nullish noop in >> spreading is a good feature to be added to the language without >> complicating it too much. >> So please take a look at the explainer >> <https://gist.github.com/askbeka/8bb17508ec250a789ea9bff683a50e38> and >> lets discuss in es-discourse proposal >> <https://es.discourse.group/t/optional-spreading-proposal/224>, if you >> have further feedback, please share >> >> On Fri, Aug 23, 2019 at 7:18 PM Herby Vojčík <herby at mailbox.sk> wrote: >> >>> On 23. 8. 2019 16:24, Beknar Askarov wrote: >>> > @Scott Rudiger After thinking more about it. >>> > I would not like to conflict with semantics of optional chaining and >>> > null coalescing operator. >>> > So in order to not confuse people, maybe introduce two types of >>> optional >>> > spread operators >>> > >>> > >>> > 1. `?...` - Do not spread if nullish. Note nullish. Else try to spread. >>> > Signature Array: [?...(nullish | Iterable)]; >>> > Signature Object: {?...(nullish | object)}; >>> > >>> > 2. `!...` - Do not spread if false. Note FALSE not falsy. Else try to >>> > spread. >>> >>> I read >>> >>> !...foo >>> >>> as >>> >>> !(...foo) >>> >>> that is, logical not. I'd tip it already works that way. In which case >>> no go, break compat. >>> >>> Herby >>> >>> > Signature Array: [!...(false | Iterable)]; >>> > Signature Object: {!...(false | object)}; >>> > >>> > I think this can be an option to avoid consfusion >>> >>> Or add a new one. :-( >>> >> _______________________________________________ > 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/20200215/03e964aa/attachment-0001.html>
No, it wouldn't - see tc39/ecma262#1069.
No, it wouldn't - see https://github.com/tc39/ecma262/pull/1069. On Sat, Feb 15, 2020 at 11:54 AM Bob Myers <rtm at gol.com> wrote: > Wouldn't simply making array spreading ignore nullish values be backward > compatible? > Unless one imagines that people are depending on this being an error > somehow. > > On Sat, Feb 15, 2020 at 10:05 AM Jordan Harband <ljharb at gmail.com> wrote: > >> Since object spread already ignores nullish values, a syntax change would >> only be needed for array spread. Then, the two kinds of spread would >> support different syntactic features, which seems inconsistent. >> >> On Sat, Feb 15, 2020 at 7:56 AM Beknar Askarov <beknaraskarov at gmail.com> >> wrote: >> >>> Thank you, everyone, for feedback. Sorry for not getting back for a >>> while. I had some time to think and concluded that nullish noop in >>> spreading is a good feature to be added to the language without >>> complicating it too much. >>> So please take a look at the explainer >>> <https://gist.github.com/askbeka/8bb17508ec250a789ea9bff683a50e38> and >>> lets discuss in es-discourse proposal >>> <https://es.discourse.group/t/optional-spreading-proposal/224>, if you >>> have further feedback, please share >>> >>> On Fri, Aug 23, 2019 at 7:18 PM Herby Vojčík <herby at mailbox.sk> wrote: >>> >>>> On 23. 8. 2019 16:24, Beknar Askarov wrote: >>>> > @Scott Rudiger After thinking more about it. >>>> > I would not like to conflict with semantics of optional chaining and >>>> > null coalescing operator. >>>> > So in order to not confuse people, maybe introduce two types of >>>> optional >>>> > spread operators >>>> > >>>> > >>>> > 1. `?...` - Do not spread if nullish. Note nullish. Else try to >>>> spread. >>>> > Signature Array: [?...(nullish | Iterable)]; >>>> > Signature Object: {?...(nullish | object)}; >>>> > >>>> > 2. `!...` - Do not spread if false. Note FALSE not falsy. Else try to >>>> > spread. >>>> >>>> I read >>>> >>>> !...foo >>>> >>>> as >>>> >>>> !(...foo) >>>> >>>> that is, logical not. I'd tip it already works that way. In which case >>>> no go, break compat. >>>> >>>> Herby >>>> >>>> > Signature Array: [!...(false | Iterable)]; >>>> > Signature Object: {!...(false | object)}; >>>> > >>>> > I think this can be an option to avoid consfusion >>>> >>>> Or add a new one. :-( >>>> >>> _______________________________________________ >> 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/20200215/7080d3e8/attachment.html>
I like it; code seems cleaner to me with its use. However, since the syntax is so similar to optional chaining, it's too bad your goal with this sample is to check for falsey values rather than nullish values.
[ 1, ?...(condition && [2, 3]), /* no extras:) */ 3, ]