tracker issue : CF-3555025

select a category, or use search below
(searches all categories and all time range)
Title:

Iterators and generators

| View in Tracker

Status/Resolution/Reason: To Fix//Investigate

Reporter/Name(from Bugbase): Adam Cameron / Adam Cameron (Adam Cameron)

Created: 05/06/2013

Components: Language

Versions: 2016,11.0,10.0

Failure Type: Enhancement Request

Found In Build/Fixed In Build: Final /

Priority/Frequency: Trivial / Unknown

Locale/System: English / Platforms All

Vote Count: 10

G'day:
I have to concede this is not a concept I have in the past thought "I rally wish CFML could do this", but havng read about it, I think it's pretty cool and would be a good addition to the language.

The description in the JS docs (https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Iterators_and_Generators) is straight forward, but basically there's two conceits:

Iterators
A standardised way of iterating over a collection. Native collection objects (eg: structs, arrays, queries, etc) would implement the Iterator interface (basically meaning it has a next() method), and components could likewise implement the interface. From there, there's a standard approach to iterating over collection objects, either manually using next(), or using a foreach() sort of loop.

Generators
This is pretty interesting. It allows for the definition of infinite sequences, by creating a function which has a yield statement in it. The function creates an iterator, and every time next)( is called on the iterator, the function is executed, returning the next element of the sequence.

Good examples are in this blog post: http://timtaubert.de/blog/2013/05/working-with-infinite-sequences-in-javascript/.

-- 
Adam

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3555025

External Customer Info:
External Company:  
External Customer Name: Adam Cameron.
External Customer Email:  
External Test Config: My Hardware and Environment details:

Attachments:

Comments:

I like the way JavaScript Iterator , Generator standardised
Vote by External U.
15488 | June 15, 2013 08:50:01 AM GMT
Excellent feature request. Thank you Adam! This would be a great feature to have for the next release.
Comment by Rupesh K.
15481 | September 05, 2013 02:22:26 AM GMT
Right, so now you're working on the next release: pls reopen this.
Comment by External U.
15482 | September 20, 2014 12:07:44 PM GMT
Why is this closed if you think this is a good idea for the next release?
Vote by External U.
15489 | September 22, 2014 10:30:10 AM GMT
Adobe, hello? Pls reopen.
Comment by External U.
15483 | October 11, 2014 06:36:33 AM GMT
Love the iterators idea - would definitely use it if it were available. Like the generators idea too, tho not exactly sure how I'd use it.
Vote by External U.
15490 | October 28, 2014 07:10:10 PM GMT
This is a language feature that languages with similar age have picked up along the way (PHP http://php.net/manual/en/language.generators.comparison.php, Javascript (already linked)) while newer languages have included from inception. https://wiki.python.org/moin/Generators http://ruby-doc.org//core-2.2.0/Enumerator.html component name="MyCollection" implements="Iterator" { variables.cursor=1; function init(max) {variables.max=max} function hasNext(){return cursor<max;} function next() { return contrived(variables.cursor); }} for(x in new MyCollection()) {} function genCollection(y) { var z =1; while (z<y) yield expensive(z++); } for(x in genCollection(5)) { writeOutput(x); } // 1234
Vote by External U.
15491 | February 23, 2015 11:54:59 AM GMT
While we don't necessarily need every language feature that javascript has, I do wish we had most of them. This one in particular is very good.
Vote by External U.
15492 | June 29, 2015 08:14:11 AM GMT
Iterators and generators are very useful in other languages (esp. generators).
Vote by External U.
15493 | June 29, 2015 11:10:20 AM GMT
Nothing constructive to add to the comments. Just getting my 25 characters in.
Vote by External U.
15494 | June 29, 2015 10:18:52 PM GMT
It is! It's the city of New New York! Strictly speaking, it's the fifteenth New York since the original, so that makes it New-New-New-New-New-New-New-New-New-New-New-New-New-New-New New York.
Vote by External U.
15495 | June 30, 2015 12:30:44 PM GMT
+1.................................................
Vote by External U.
15496 | October 01, 2015 12:54:10 PM GMT
+1 ......................
Vote by External U.
15497 | October 03, 2015 08:04:15 PM GMT
This would be considered for the next release
Comment by Rupesh K.
15484 | October 26, 2015 08:55:24 PM GMT
"Next"? Like 12, or 13? Can you guys pls dispense with using the term "next" without qualification? You could say "12" or "next after 11", or "has missed the boat for 12, so we'll look at it for 13". Remember that "communication" is about delivering information to the other party.
Comment by External U.
15485 | October 27, 2015 01:01:01 AM GMT
That would be the next after 12.
Comment by Rupesh K.
15486 | October 27, 2015 09:06:12 PM GMT
Cool, cheers for the clarification. Can you make a point ("you" plural: ie: the team) of being that clear when discussing versions from now on. BTW, I believe the "next after 12" might be "13" ;-)
Comment by External U.
15487 | October 28, 2015 02:42:58 AM GMT