Re: Re: Proposal: Conditional `catch` in Promises

2018-04-25 Thread Ayush Gupta
It might be worth **explicitly** mentioning that it's not about types
either, the benefit with using functions as the filter is that we can
tackle a lot of cases. Consider this:

```js
return somePromise
.catch((reason) => reason instanceof ValidationError, reason =>
handleValidationError(reason))
.catch((reason) => reason.code === 'ENOENT', reason =>
handleENOENT(reason))
.catch(reason => handleOtherErrors(reason)) // catch all others
```


On Wed, Apr 25, 2018 at 10:25 PM, Bob Myers  wrote:

> What do you mean by "approach TypeScript"? Do you mean propose this
> feature to the TS team? TS is not about new language features (with a few
> exceptions). It's about typing. They're quite careful about not forking the
> language.
>
> >  Not sure if that supports typed errors
>
> No, it doesn't.
>
> Bob
>
> On Wed, Apr 25, 2018 at 9:49 PM, Michael J. Ryan 
> wrote:
>
>> Maybe approach typescript on this one... Not sure if that supports typed
>> errors like C# does, but would probably suit you well.
>>
>> On Wed, Apr 25, 2018, 08:31 Isiah Meadows  wrote:
>>
>>> I'd still prefer we wait until pattern matching [1] gets addressed
>>> first, then tackling this. Error types are represented about 50 different
>>> ways in JS, with subtyping only being one (used by the standard kind of).
>>> Node appends an `err.code`, and the DOM adds a similar type, just using a
>>> common error subclass. And in some cases where errors are planned (but
>>> exceptions are more convenient), you sometimes see non-errors thrown. So
>>> there needs to be a means of catching all of them, and `if` checks get
>>> verbose and noisy in a hurry.
>>>
>>> On Wed, Apr 25, 2018, 00:11 Ayush Gupta  wrote:
>>>
 We could potentially provide the same functionality in `try/catch` by
 extending the signature of `catch` to

 ```js
 try {

 } catch(, ) {

 }
 ```

 If `` evaluates to truthy, invoke the `catch`
 block, otherwise don't.
 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss

>>> ___
>>> es-discuss mailing list
>>> es-discuss@mozilla.org
>>> https://mail.mozilla.org/listinfo/es-discuss
>>>
>>
>> ___
>> es-discuss mailing list
>> es-discuss@mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>>
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Re: Proposal: Conditional `catch` in Promises

2018-04-25 Thread Bob Myers
What do you mean by "approach TypeScript"? Do you mean propose this feature
to the TS team? TS is not about new language features (with a few
exceptions). It's about typing. They're quite careful about not forking the
language.

>  Not sure if that supports typed errors

No, it doesn't.

Bob

On Wed, Apr 25, 2018 at 9:49 PM, Michael J. Ryan  wrote:

> Maybe approach typescript on this one... Not sure if that supports typed
> errors like C# does, but would probably suit you well.
>
> On Wed, Apr 25, 2018, 08:31 Isiah Meadows  wrote:
>
>> I'd still prefer we wait until pattern matching [1] gets addressed first,
>> then tackling this. Error types are represented about 50 different ways in
>> JS, with subtyping only being one (used by the standard kind of). Node
>> appends an `err.code`, and the DOM adds a similar type, just using a common
>> error subclass. And in some cases where errors are planned (but exceptions
>> are more convenient), you sometimes see non-errors thrown. So there needs
>> to be a means of catching all of them, and `if` checks get verbose and
>> noisy in a hurry.
>>
>> On Wed, Apr 25, 2018, 00:11 Ayush Gupta  wrote:
>>
>>> We could potentially provide the same functionality in `try/catch` by
>>> extending the signature of `catch` to
>>>
>>> ```js
>>> try {
>>>
>>> } catch(, ) {
>>>
>>> }
>>> ```
>>>
>>> If `` evaluates to truthy, invoke the `catch`
>>> block, otherwise don't.
>>> ___
>>> es-discuss mailing list
>>> es-discuss@mozilla.org
>>> https://mail.mozilla.org/listinfo/es-discuss
>>>
>> ___
>> es-discuss mailing list
>> es-discuss@mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Proposal: spread assignment operator

2018-04-25 Thread Jeremy Martin
By way of context, some similar ideas have been previously discussed:

   -
   
https://esdiscuss.org/topic/picking-deconstructing-properties-into-object-literals
   -
   
https://esdiscuss.org/topic/destructuring-an-object-into-a-new-object-like-underscore-pick-but-esier
   -
   https://esdiscuss.org/topic/extended-dot-notation-pick-notation-proposal

FWIW, I actually do like the idea of being able to syntactically "reshape"
one object or array directly into another, and there's probably even a
cowpath argument to be made on the basis of so many `pick()`, `omit()`,
etc. implementations out there. On the other hand, per Isiah's comments,
we're at least 90% there already with Object.assign(), so it seems like the
value proposition could/should be developed a bit more on this.

On Wed, Apr 25, 2018 at 12:29 PM, Arutyunyan Artyom  wrote:

>
> I think it can be looks like: https://gist.github.com/artalar/
> ea8512546a3675648615a25e846096a6
>
> 25.04.2018, 18:58, "Isiah Meadows" :
>
> It doesn't. But with objects, it's not a cheap operation to simply
> duplicate, and they aren't normally immutable like primitives. Furthermore,
> why is it for objects, not arrays?
>
> (I'm pushing that second question as a point of potential confusion -
> remember the user.)
>
> On Wed, Apr 25, 2018, 11:45 Arutyunyan Artyom  wrote:
>
> spread assignment not mutate, it reassign, like "+=" and other.
>
> if (
> ('a = {...a,...b}'.length > 'a ...= b'.length) === ('n = n+1'.length > 'n
> += 1'.length)
> ) { console.log('why "addition assignment" is necessary, but "spread
> assignment" is not?'); }
>
>
>
>
> 25.04.2018, 18:21, "Isiah Meadows" :
>
> Note: `Object.assign` mutates its first argument and (with only obscure
> caveats) does exactly this. Not sure syntax is necessary here.
>
> Oh, and arrays also have the common idiom `array.push(...values)` (but
> they could use an `Array.prototype.pushAll` to avoid polluting arguments
> lists).
>
> On Wed, Apr 25, 2018, 09:24 Артём Арутюнян  wrote:
>
> I propose *spread assignment operator*:
>
> *var obj = { test1: 1 };*
> *var anotherObj = { test2: 2 };*
> *obj ...= { test2: 2 }; // == (obj = { ...obj, ...anotherObj })*
> *// { test1: 1, test2: 2 }*
>
> I'm surprised it wasn't in the original implementation
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>


-- 
Jeremy Martin
661.312.3853
@jmar777  / @j 
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Proposal: spread assignment operator

2018-04-25 Thread Arutyunyan Artyom
 I think it can be looks like: https://gist.github.com/artalar/ea8512546a3675648615a25e846096a6 25.04.2018, 18:58, "Isiah Meadows" :It doesn't. But with objects, it's not a cheap operation to simply duplicate, and they aren't normally immutable like primitives. Furthermore, why is it for objects, not arrays? (I'm pushing that second question as a point of potential confusion - remember the user.) On Wed, Apr 25, 2018, 11:45 Arutyunyan Artyom  wrote:spread assignment not mutate, it reassign, like "+=" and other. if (('a = {...a,...b}'.length > 'a ...= b'.length) === ('n = n+1'.length > 'n += 1'.length)) { console.log('why "addition assignment" is necessary, but "spread assignment" is not?'); }   25.04.2018, 18:21, "Isiah Meadows" :Note: `Object.assign` mutates its first argument and (with only obscure caveats) does exactly this. Not sure syntax is necessary here. Oh, and arrays also have the common idiom `array.push(...values)` (but they could use an `Array.prototype.pushAll` to avoid polluting arguments lists). On Wed, Apr 25, 2018, 09:24 Артём Арутюнян  wrote:I propose spread assignment operator: var obj = { test1: 1 };var anotherObj = { test2: 2 };obj ...= { test2: 2 }; // == (obj = { ...obj, ...anotherObj })// { test1: 1, test2: 2 } I'm surprised it wasn't in the original implementation___es-discuss mailing listes-discuss@mozilla.orghttps://mail.mozilla.org/listinfo/es-discuss___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Re: Proposal: Conditional `catch` in Promises

2018-04-25 Thread Michael J. Ryan
Maybe approach typescript on this one... Not sure if that supports typed
errors like C# does, but would probably suit you well.

On Wed, Apr 25, 2018, 08:31 Isiah Meadows  wrote:

> I'd still prefer we wait until pattern matching [1] gets addressed first,
> then tackling this. Error types are represented about 50 different ways in
> JS, with subtyping only being one (used by the standard kind of). Node
> appends an `err.code`, and the DOM adds a similar type, just using a common
> error subclass. And in some cases where errors are planned (but exceptions
> are more convenient), you sometimes see non-errors thrown. So there needs
> to be a means of catching all of them, and `if` checks get verbose and
> noisy in a hurry.
>
> On Wed, Apr 25, 2018, 00:11 Ayush Gupta  wrote:
>
>> We could potentially provide the same functionality in `try/catch` by
>> extending the signature of `catch` to
>>
>> ```js
>> try {
>>
>> } catch(, ) {
>>
>> }
>> ```
>>
>> If `` evaluates to truthy, invoke the `catch` block,
>> otherwise don't.
>> ___
>> es-discuss mailing list
>> es-discuss@mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Proposal: spread assignment operator

2018-04-25 Thread Isiah Meadows
It doesn't. But with objects, it's not a cheap operation to simply
duplicate, and they aren't normally immutable like primitives. Furthermore,
why is it for objects, not arrays?

(I'm pushing that second question as a point of potential confusion -
remember the user.)

On Wed, Apr 25, 2018, 11:45 Arutyunyan Artyom  wrote:

> spread assignment not mutate, it reassign, like "+=" and other.
>
> if (
> ('a = {...a,...b}'.length > 'a ...= b'.length) === ('n = n+1'.length > 'n
> += 1'.length)
> ) { console.log('why "addition assignment" is necessary, but "spread
> assignment" is not?'); }
>
>
>
> 25.04.2018, 18:21, "Isiah Meadows" :
>
> Note: `Object.assign` mutates its first argument and (with only obscure
> caveats) does exactly this. Not sure syntax is necessary here.
>
> Oh, and arrays also have the common idiom `array.push(...values)` (but
> they could use an `Array.prototype.pushAll` to avoid polluting arguments
> lists).
>
> On Wed, Apr 25, 2018, 09:24 Артём Арутюнян  wrote:
>
> I propose *spread assignment operator*:
>
> *var obj = { test1: 1 };*
> *var anotherObj = { test2: 2 };*
> *obj ...= { test2: 2 }; // == (obj = { ...obj, ...anotherObj })*
> *// { test1: 1, test2: 2 }*
>
> I'm surprised it wasn't in the original implementation
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Proposal: spread assignment operator

2018-04-25 Thread Arutyunyan Artyom
spread assignment not mutate, it reassign, like "+=" and other. if (('a = {...a,...b}'.length > 'a ...= b'.length) === ('n = n+1'.length > 'n += 1'.length)) { console.log('why "addition assignment" is necessary, but "spread assignment" is not?'); }   25.04.2018, 18:21, "Isiah Meadows" :Note: `Object.assign` mutates its first argument and (with only obscure caveats) does exactly this. Not sure syntax is necessary here. Oh, and arrays also have the common idiom `array.push(...values)` (but they could use an `Array.prototype.pushAll` to avoid polluting arguments lists). On Wed, Apr 25, 2018, 09:24 Артём Арутюнян  wrote:I propose spread assignment operator: var obj = { test1: 1 };var anotherObj = { test2: 2 };obj ...= { test2: 2 }; // == (obj = { ...obj, ...anotherObj })// { test1: 1, test2: 2 } I'm surprised it wasn't in the original implementation___es-discuss mailing listes-discuss@mozilla.orghttps://mail.mozilla.org/listinfo/es-discuss___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Re: Proposal: Conditional `catch` in Promises

2018-04-25 Thread Isiah Meadows
I'd still prefer we wait until pattern matching [1] gets addressed first,
then tackling this. Error types are represented about 50 different ways in
JS, with subtyping only being one (used by the standard kind of). Node
appends an `err.code`, and the DOM adds a similar type, just using a common
error subclass. And in some cases where errors are planned (but exceptions
are more convenient), you sometimes see non-errors thrown. So there needs
to be a means of catching all of them, and `if` checks get verbose and
noisy in a hurry.

On Wed, Apr 25, 2018, 00:11 Ayush Gupta  wrote:

> We could potentially provide the same functionality in `try/catch` by
> extending the signature of `catch` to
>
> ```js
> try {
>
> } catch(, ) {
>
> }
> ```
>
> If `` evaluates to truthy, invoke the `catch` block,
> otherwise don't.
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Proposal: spread assignment operator

2018-04-25 Thread Isiah Meadows
Note: `Object.assign` mutates its first argument and (with only obscure
caveats) does exactly this. Not sure syntax is necessary here.

Oh, and arrays also have the common idiom `array.push(...values)` (but they
could use an `Array.prototype.pushAll` to avoid polluting arguments lists).

On Wed, Apr 25, 2018, 09:24 Артём Арутюнян  wrote:

> I propose *spread assignment operator*:
>
> *var obj = { test1: 1 };*
> *var anotherObj = { test2: 2 };*
> *obj ...= { test2: 2 }; // == (obj = { ...obj, ...anotherObj })*
> *// { test1: 1, test2: 2 }*
>
> I'm surprised it wasn't in the original implementation
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Proposal: spread assignment operator

2018-04-25 Thread Артём Арутюнян
I propose spread assignment operator: var obj = { test1: 1 };var anotherObj = { test2: 2 };obj ...= { test2: 2 }; // == (obj = { ...obj, ...anotherObj })// { test1: 1, test2: 2 } I'm surprised it wasn't in the original implementation
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss