{"id":120,"date":"2009-07-02T22:43:48","date_gmt":"2009-07-02T20:43:48","guid":{"rendered":"http:\/\/blog.ansuz.nl\/?p=120"},"modified":"2009-07-02T22:43:48","modified_gmt":"2009-07-02T20:43:48","slug":"haxe-iterators","status":"publish","type":"post","link":"http:\/\/blog.ansuz.nl\/index.php\/2009\/07\/02\/haxe-iterators\/","title":{"rendered":"HaXe Iterators"},"content":{"rendered":"<div id=\"ig-sh-1\" class=\"syntax_hilite\">\n\n\t\t<div class=\"toolbar\">\n\n\t\t<div class=\"view-different-container\">\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t<div class=\"language-name\">ActionScript<\/div>\n\n\t\t\n\t\t<br clear=\"both\">\n\n\t<\/div>\n\t\n\t<div class=\"code\">\n\t\t<ol class=\"actionscript\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000000;font-weight: bold\">var<\/span> myHash:Hash<span style=\"color: #66cc66\">&amp;<\/span>lt;Int<span style=\"color: #66cc66\">&amp;<\/span>gt; = <span style=\"color: #000000;font-weight: bold\">new<\/span> Hash<span style=\"color: #66cc66\">&#040;<\/span><span style=\"color: #66cc66\">&#041;<\/span>;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">myHash.<span style=\"color: #0066CC\">set<\/span><span style=\"color: #66cc66\">&#040;<\/span><span style=\"color: #ff0000\">&quot;one&quot;<\/span>, <span style=\"color: #cc66cc\">1<\/span><span style=\"color: #66cc66\">&#041;<\/span>;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">myHash.<span style=\"color: #0066CC\">set<\/span><span style=\"color: #66cc66\">&#040;<\/span><span style=\"color: #ff0000\">&quot;two&quot;<\/span>, <span style=\"color: #cc66cc\">1<\/span><span style=\"color: #66cc66\">&#041;<\/span>;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">myHash.<span style=\"color: #0066CC\">set<\/span><span style=\"color: #66cc66\">&#040;<\/span><span style=\"color: #ff0000\">&quot;three&quot;<\/span>, <span style=\"color: #cc66cc\">2<\/span><span style=\"color: #66cc66\">&#041;<\/span>;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">myHash.<span style=\"color: #0066CC\">set<\/span><span style=\"color: #66cc66\">&#040;<\/span><span style=\"color: #ff0000\">&quot;four&quot;<\/span>, <span style=\"color: #cc66cc\">3<\/span><span style=\"color: #66cc66\">&#041;<\/span>;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">myHash.<span style=\"color: #0066CC\">set<\/span><span style=\"color: #66cc66\">&#040;<\/span><span style=\"color: #ff0000\">&quot;five&quot;<\/span>, <span style=\"color: #cc66cc\">5<\/span><span style=\"color: #66cc66\">&#041;<\/span>;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000000;font-weight: bold\">var<\/span> total:<span style=\"color: #0066CC\">Int<\/span> = <span style=\"color: #cc66cc\">0<\/span>;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #b1b100\">for<\/span> <span style=\"color: #66cc66\">&#040;<\/span> num <span style=\"color: #b1b100\">in<\/span> myHash.<span style=\"color: #006600\">iterator<\/span><span style=\"color: #66cc66\">&#040;<\/span><span style=\"color: #66cc66\">&#041;<\/span> <span style=\"color: #66cc66\">&#041;<\/span> <span style=\"color: #66cc66\">&#123;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">total += num;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #0066CC\">trace<\/span><span style=\"color: #66cc66\">&#040;<\/span>num + <span style=\"color: #ff0000\">&quot;: &quot;<\/span> + total<span style=\"color: #66cc66\">&#041;<\/span>;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #66cc66\">&#125;<\/span><\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<blockquote><p>In computer science, an iterator is an object that allows a programmer to traverse through all the elements of a collection, regardless of its specific implementation. An iterator is sometimes called a cursor, especially within the context of a database.<br \/>\n&#8211; <a href=\"http:\/\/en.wikipedia.org\/wiki\/Iterator\" target=\"_blank\">From Wikipedia<\/a> &#8211;<\/p><\/blockquote>\n<p>In this particular example you don&#8217;t need to use .iterator() as the Hash class is iterable, see <a href=\"http:\/\/haxe.org\/ref\/iterators\" target=\"_blank\">http:\/\/haxe.org\/ref\/iterators<\/a> &gt; &#8216;Iterable Objects&#8217;.<\/p>\n<p><strong>NOTE:<\/strong> Use myHash.iterator() (mind the parenthesis) and not myHash.iterator as I&#8217;m used to from coding AS3.<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>&lt; View plain text &gt; ActionScript var myHash:Hash&amp;lt;Int&amp;gt; = new Hash&#040;&#041;; myHash.set&#040;&quot;one&quot;, 1&#041;; myHash.set&#040;&quot;two&quot;, 1&#041;; myHash.set&#040;&quot;three&quot;, 2&#041;; myHash.set&#040;&quot;four&quot;, 3&#041;; myHash.set&#040;&quot;five&quot;, 5&#041;; &nbsp; var total:Int = 0; &nbsp; for &#040; num in myHash.iterator&#040;&#041; &#041; &#123; total += num; trace&#040;num + &quot;: &hellip; <a href=\"http:\/\/blog.ansuz.nl\/index.php\/2009\/07\/02\/haxe-iterators\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[90],"tags":[],"class_list":["post-120","post","type-post","status-publish","format-standard","hentry","category-haxe"],"_links":{"self":[{"href":"http:\/\/blog.ansuz.nl\/index.php\/wp-json\/wp\/v2\/posts\/120","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.ansuz.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.ansuz.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.ansuz.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.ansuz.nl\/index.php\/wp-json\/wp\/v2\/comments?post=120"}],"version-history":[{"count":2,"href":"http:\/\/blog.ansuz.nl\/index.php\/wp-json\/wp\/v2\/posts\/120\/revisions"}],"predecessor-version":[{"id":122,"href":"http:\/\/blog.ansuz.nl\/index.php\/wp-json\/wp\/v2\/posts\/120\/revisions\/122"}],"wp:attachment":[{"href":"http:\/\/blog.ansuz.nl\/index.php\/wp-json\/wp\/v2\/media?parent=120"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.ansuz.nl\/index.php\/wp-json\/wp\/v2\/categories?post=120"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.ansuz.nl\/index.php\/wp-json\/wp\/v2\/tags?post=120"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}