Return value of forEach

2015-10-16 Thread Niloy Mondal
Currently, `Array.prototype.forEach` returns `undefined`. It would be more
useful if it returns the array itself.

Say I have written some code like this...

```js
const a = [1, 2, 3]
  .map(square)
  .map(plus1)
  .reduce(add);
```

For some reason, I am not getting the expected output. For debugging, I
would
like the print the values after each step. My first initial reaction is to
put a `forEach` step in between and print the values like so...

```js
const a = [1, 2, 3]
  .map(square)
  .forEach(x => console.log(x))
  .map(plus1)
  .reduce(add);
```

Unfortunately, this does not work as `forEach` returns `undefined`. I now
have
to comment out all the code below it. Having the _plug and play_ behaviour
for
`forEach` would be very convenient.
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Return value of forEach

2015-10-16 Thread Niloy Mondal
> That'd be a compatibility break.

Ugh... you mean people actually depend on `forEach` returning `undefined`
(which it always does) to do further task?

I wonder what that kinda code would look like >.<

On Fri, Oct 16, 2015 at 6:08 PM, Frankie Bagnardi <f.bagna...@gmail.com>
wrote:

> That'd be a compatibility break.
>
> If we end up getting :: though:
>
> ```js
> function logEach(){
>   this.forEach((x) => console.log(x));
>   return this;
> }
>
>
> const a = [1, 2, 3]
>   .map(square)
>   ::logEach()
>   .map(plus1)
>   .reduce(add);
> ```
>
> You could make that a global variable so you can sprinkle it around your
> code in development.
>
> Having some developer tools in the language would be nice though. I don't
> even think console.log is in the spec. A global like Debug.logThis for
> example would be a more general ::-able.
>
>
> On Fri, Oct 16, 2015 at 5:32 AM, Andrea Giammarchi <
> andrea.giammar...@gmail.com> wrote:
>
>> ```js
>> const a = [1, 2, 3]
>>   .map(square)
>>   .map(x => console.log(x) || x )
>>   .map(plus1)
>>   .reduce(add);
>> ```
>>
>> Regards
>>
>>
>> On Fri, Oct 16, 2015 at 10:13 AM, Niloy Mondal <niloy.monda...@gmail.com>
>> wrote:
>>
>>> Currently, `Array.prototype.forEach` returns `undefined`. It would be
>>> more
>>> useful if it returns the array itself.
>>>
>>> Say I have written some code like this...
>>>
>>> ```js
>>> const a = [1, 2, 3]
>>>   .map(square)
>>>   .map(plus1)
>>>   .reduce(add);
>>> ```
>>>
>>> For some reason, I am not getting the expected output. For debugging, I
>>> would
>>> like the print the values after each step. My first initial reaction is
>>> to
>>> put a `forEach` step in between and print the values like so...
>>>
>>> ```js
>>> const a = [1, 2, 3]
>>>   .map(square)
>>>   .forEach(x => console.log(x))
>>>   .map(plus1)
>>>   .reduce(add);
>>> ```
>>>
>>> Unfortunately, this does not work as `forEach` returns `undefined`. I
>>> now have
>>> to comment out all the code below it. Having the _plug and play_
>>> behaviour for
>>> `forEach` would be very convenient.
>>>
>>> ___
>>> 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


Curried functions

2015-10-15 Thread Niloy Mondal
It would be really cool to have syntax to curry functions built into the
languages. Something like...

```js
curry function add(a, b) {
return a + b;
}

add(2)(3); // 5
```
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Exponentiation operator precedence

2015-08-27 Thread Niloy Mondal
x ** y ** z is easier to read/write than x.pow(y.pow(z))
On Aug 27, 2015 8:51 AM, Mark S. Miller erig...@google.com wrote:



 On Wed, Aug 26, 2015 at 6:19 PM, Waldemar Horwat walde...@google.com
 wrote:

 On 08/26/2015 15:08, Mark S. Miller wrote:

 The force of that precedent is indeed what my objection is. The yield
 counter-example is interesting, but yield is an identifier not an
 operator symbol, and so does not as clearly fall within or shape operator
 expectations.

 If someone explains a compelling need for ** I would find that
 interesting. But until then...


 ** is a convenience, and that's the wrong criterion to apply here.  If it
 were, then we wouldn't have useful conveniences like Math.cosh or arrow
 functions.

 I'd rather read

   a*x**3 + b*x**2 + c*x + d

 than

   a*Math.pow(x, 3) + b*Math.pow(x, 2) + c*x + d





 Ok, we have a benefit to evaluate. Brevity. With the example contrast
 between

 a*x**3 + b*x**2 + c*x + d

 and

 a*Math.pow(x, 3) + b*Math.pow(x, 2) + c*x + d

 Let's also apply Alexander's suggestion

 a*x.pow(3) + b*x.pow(2) + c*x + d

 To help us compare for brevity, and because I'm too lazy to count, I'm
 sending it in a fixed width font.


 --
 Cheers,
 --MarkM

 ___
 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


this value inside anonymous generator

2015-03-31 Thread Niloy Mondal
I wrote some code like the following in tracuer

```
class Foo {
  constructor() {
spawn(function*() {
  let data = yield this.fetchData(); // error because 'this' is
undefined
});
  }

  fetchData() {
// returns promise
  }
}
```

I used the spawn function from here:
https://gist.github.com/jakearchibald/31b89cba627924972ad6

The code doesn't work because 'this' is undefined. I can fix it by using
'let that = this' pattern. But it feels like a step backward now that I've
fallen in love with lambda functions. So I was wondering if it would be
possible to use lexical binding for 'this' inside anonymous generators.
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Single destructuring argument to an arrow function

2015-03-20 Thread Niloy Mondal
Really awesome if we could have this feature.

On Sat, Mar 21, 2015 at 4:04 AM, Brendan Eich bren...@mozilla.org wrote:

 But we could extend the cover grammar with some work. You'd have to push
 ArrayLiteral and ObjectLiteral down from PrimaryExpression alternative
 right-hand sides, to live under 
 CoverParenthesizedExpressionAndArrowParameterList.Seems
 do-able -- anyone see a fatal problem? Could be an ES7 relaxation from ES6,
 if it matters enough to users.

 /be

 Rick Waldron wrote:

 Inline...


 On Thu, Mar 19, 2015 at 4:50 PM Jan-Ivar Bruaroey j...@mozilla.com
 mailto:j...@mozilla.com wrote:

 Hi group! First post, so be gentle.


 Welcome


 I love how arrow functions allow single arguments to be passed without
 parenthesis, so I expected this to work:

  Promise.all([true, false]).then([foo, bar] = console.log(foo +”,
 + bar));

 but it doesn't:

  SyntaxError: invalid arrow-function arguments (parentheses around
 the arrow-function may help)

 I understand from the spec that this is as defined, but is there a
 technical reason to disallow it?


 To prevent ambiguity with:

 MemberExpressionArguments
 CallExpressionArguments


 Arguments[Yield] :
 |(| |)|
 |(| ArgumentList[?Yield] |)|
 ArgumentList[Yield] :
 AssignmentExpression[In, ?Yield]
 |...| AssignmentExpression[In, ?Yield]
 ArgumentList[?Yield] |,| AssignmentExpression[In, ?Yield]
 ArgumentList[?Yield] |,| |...| AssignmentExpression[In, ?Yield]


 e.g.

   fn([a, b])

 Rick


 The parenthesis seem redundant to the naked eye.

 Thanks,

 .: Jan-Ivar :.

 ___
 es-discuss mailing list
 es-discuss@mozilla.org mailto: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


how to delay interpolation of template strings?

2014-12-16 Thread Niloy Mondal
I want to define a template string using backquotes in a different file and
then have it interpolated with actual values in a different file. How can I
do it?
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: how to delay interpolation of template strings?

2014-12-16 Thread Niloy Mondal
Thanks, this would work.

How can I construct a template string dynamically? Like reading the
template from a file/database and then interpolate it.

On Tue, Dec 16, 2014 at 2:29 PM, Claude Pache claude.pa...@gmail.com
wrote:


 Le 16 déc. 2014 à 09:27, Niloy Mondal niloy.monda...@gmail.com a écrit :

 I want to define a template string using backquotes in a different file
 and then have it interpolated with actual values in a different file. How
 can I do it?


 Just enclose it in a function:

 ```javascript
function foo(a) {
 return `some template ${a}`
 }

 foo(bar) // will evaluate `some template ${bar}`
 ```

 —Claude

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


Re: how to delay interpolation of template strings?

2014-12-16 Thread Niloy Mondal
Can this be considered for a feature request? Provision in the language to
dynamically construct template strings and interpolate them.

On Tue, Dec 16, 2014 at 4:48 PM, Andrea Giammarchi 
andrea.giammar...@gmail.com wrote:

 irony ... I think you would need to evaluate the template string inline in
 order to interpolate its result ...

 OR

 you just go for this method which also works down to ES3 engine:
 https://gist.github.com/WebReflection/8f227532143e63649804

 Regards

 On Tue, Dec 16, 2014 at 10:01 AM, Niloy Mondal niloy.monda...@gmail.com
 wrote:

 Thanks, this would work.

 How can I construct a template string dynamically? Like reading the
 template from a file/database and then interpolate it.

 On Tue, Dec 16, 2014 at 2:29 PM, Claude Pache claude.pa...@gmail.com
 wrote:


 Le 16 déc. 2014 à 09:27, Niloy Mondal niloy.monda...@gmail.com a
 écrit :

 I want to define a template string using backquotes in a different file
 and then have it interpolated with actual values in a different file. How
 can I do it?


 Just enclose it in a function:

 ```javascript
function foo(a) {
 return `some template ${a}`
 }

 foo(bar) // will evaluate `some template ${bar}`
 ```

 —Claude


 ___
 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