Suggestion: for-of-and loops
# Kevin Smith (10 years ago)
Have you tried writing a combinator which does exactly that? Take a look at zip in python.
Have you tried writing a combinator which does exactly that? Take a look at zip in python. On Feb 14, 2015 2:52 PM, "Brian Blakely" <anewpage.media at gmail.com> wrote: > Apologies if this isn't the correct forum for this, and please point me > the right way if not. > > The motivation is that it would be useful if one could tersely loop over > multiple iterators simultaneously. I think this could be accomplished with > a "for-of-and" syntax. > > Example: > > let temp = [80, 35, 20]; > > let cond = ['sunny', 'cloudy']; > > for(let [t, c] of temp and cond) { > console.log(t, c); > // first: 80 'sunny' > // second: 35 'cloudy' > // third: 20 undefined > } > > As above, this is useful when we have two separate but related data sets. > It becomes more powerful as the data sets become more complex. > > Example: > > let forecast1 = [ > { > "highTemp": "90", > "lowTemp": "70" > }, > { > "highTemp": "92", > "lowTemp": "82" > }, > // etc... > ]; > > let forecast2 = [ > { > "high": "85", > "low": "68", > "condition": "partiallycloudy" > }, > { > "high": "95", > "low": "80", > "condition": "sunny" > }, > // etc... > ]; > > for(let [f1, f2] of forecast1 and forecast2) { > console.log(average(f1.highTemp, f2.high)); > } > > Thanks for reading! > > _______________________________________________ > 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/20150214/9b8403a4/attachment-0001.html>
# Brian Blakely (10 years ago)
That is basically what I have done in practice.
That is basically what I have done in practice. On Sat, Feb 14, 2015 at 2:59 PM, Kevin Smith <zenparsing at gmail.com> wrote: > Have you tried writing a combinator which does exactly that? Take a look > at zip in python. > On Feb 14, 2015 2:52 PM, "Brian Blakely" <anewpage.media at gmail.com> wrote: > >> Apologies if this isn't the correct forum for this, and please point me >> the right way if not. >> >> The motivation is that it would be useful if one could tersely loop over >> multiple iterators simultaneously. I think this could be accomplished with >> a "for-of-and" syntax. >> >> Example: >> >> let temp = [80, 35, 20]; >> >> let cond = ['sunny', 'cloudy']; >> >> for(let [t, c] of temp and cond) { >> console.log(t, c); >> // first: 80 'sunny' >> // second: 35 'cloudy' >> // third: 20 undefined >> } >> >> As above, this is useful when we have two separate but related data >> sets. It becomes more powerful as the data sets become more complex. >> >> Example: >> >> let forecast1 = [ >> { >> "highTemp": "90", >> "lowTemp": "70" >> }, >> { >> "highTemp": "92", >> "lowTemp": "82" >> }, >> // etc... >> ]; >> >> let forecast2 = [ >> { >> "high": "85", >> "low": "68", >> "condition": "partiallycloudy" >> }, >> { >> "high": "95", >> "low": "80", >> "condition": "sunny" >> }, >> // etc... >> ]; >> >> for(let [f1, f2] of forecast1 and forecast2) { >> console.log(average(f1.highTemp, f2.high)); >> } >> >> Thanks for reading! >> >> _______________________________________________ >> 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/20150214/286fd9d7/attachment.html>
# Brendan Eich (10 years ago)
Kevin Smith wrote:
Have you tried writing a combinator which does exactly that? Take a look at zip in python.
Right -- we don't add new syntax lightly, we'd need to see zip used a lot, and at some irreducible-without-special-form overhead.
Kevin Smith wrote: > > Have you tried writing a combinator which does exactly that? Take a > look at zip in python. > Right -- we don't add new syntax lightly, we'd need to see zip used a lot, and at some irreducible-without-special-form overhead. /be
# Brian Blakely (10 years ago)
Thank you for that insight
Thank you for that insight On Sun, Feb 15, 2015 at 10:10 PM, Brendan Eich <brendan at mozilla.org> wrote: > Kevin Smith wrote: > >> >> Have you tried writing a combinator which does exactly that? Take a look >> at zip in python. >> >> > Right -- we don't add new syntax lightly, we'd need to see zip used a lot, > and at some irreducible-without-special-form overhead. > > /be > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150217/53f096d4/attachment-0001.html>
Apologies if this isn't the correct forum for this, and please point me the right way if not.
The motivation is that it would be useful if one could tersely loop over multiple iterators simultaneously. I think this could be accomplished with a "for-of-and" syntax.
Example:
let temp = [80, 35, 20];
let cond = ['sunny', 'cloudy'];
for(let [t, c] of temp and cond) { console.log(t, c); // first: 80 'sunny' // second: 35 'cloudy' // third: 20 undefined }
As above, this is useful when we have two separate but related data sets. It becomes more powerful as the data sets become more complex.
Example:
let forecast1 = [ { "highTemp": "90", "lowTemp": "70" }, { "highTemp": "92", "lowTemp": "82" }, // etc... ];
let forecast2 = [ { "high": "85", "low": "68", "condition": "partiallycloudy" }, { "high": "95", "low": "80", "condition": "sunny" }, // etc... ];
for(let [f1, f2] of forecast1 and forecast2) { console.log(average(f1.highTemp, f2.high)); }
Thanks for reading!