for statement with index and value
Sébastien Doeraene
sjrdoeraene at gmail.com
Tue Jul 14 19:13:16 UTC 2015
Hi,
And it's called zipWithIndex in Scala:
```scala
for ((value, i) <- someTraversable.zipWithIndex) {
// do stuff
}
```
And, in Ruby, it's each_with_index:
```ruby
for value, i in someArray.each_with_index
# do stuff
end
```
I see a pattern, here. It seems several other languages are pretty fine
with a simple method that bundles elements of a collection with their
indices, and then rely on destructuring on the left-hand-side of their for
loop to extract them again, instead of adding additional syntax for this
use case. IMO, that's a strong argument for doing the same thing in ES.
Cheers,
Sébastien
I think there's something
On Tue, Jul 14, 2015 at 8:49 PM, Alexander Jones <alex at weej.com> wrote:
> It's called `enumerate` in Python. And it's trivial to implement:
>
> ```js
> for (let [i, value] of enumerate(someIterable)) {
> // behold...
> }
> ```
>
> On Tuesday, July 14, 2015, Domenic Denicola <d at domenic.me> wrote:
>
>> From: Tingan Ho [mailto:tingan87 at gmail.com]
>>
>> > But they aren't clean solutions to a wildly popular problem.
>>
>> I disagree.
>> _______________________________________________
>> 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/20150714/1ae46077/attachment-0001.html>
More information about the es-discuss
mailing list