<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                使用Haxe,很容易定義定制的迭代器和可迭代數據類型。這些概念分別由類型 Iterator<T> 和 Iterable<T>為代表: > With Haxe it is very easy to de?ne custom iterators and iterable data types. These concepts are represented by the types Iterator<T> and Iterable<T> respectively: ~~~ typedef Iterator<T> = { function hasNext() : Bool; function next() : T; } typedef Iterable<T> = { function iterator() : Iterator<T>; } ~~~ 任何在結構上和這些類型合一(第3.5.2節)的類都可以被通過使用 for循環迭代。也就是說,如果類定義了方法 hasNet 和 next包括匹配的返回類型,都可以被認為是一個迭代器,如果它定義了一個方法 iterator 返回一個 Iterator<T>,則被認為是可迭代類型。 > Any class (2.3) which structurally uni?es (3.5.2) with one of these types can be iterated over usingafor-loop(5.13). Thatis,if the class de?nes methods hasNext and next with matching return types it is considered an iterator,if it de?nes a method iterator returning an Iterator<T> it is considered an iterable type. ~~~ class MyStringIterator { var s:String; var i:Int; public function new(s:String) { this.s = s; i = 0; } public function hasNext() { return i < s.length; } public function next() { return s.charAt(i++); } } class Main { static public function main() { var myIt = new MyStringIterator("string"); for (chr in myIt) { trace(chr); } } } ~~~ 本例中的類型 MyStringIterator 有資格作為迭代器:它定義了一個方法 hasNext,返回Bool,和一個方法 next,返回String,使它兼容于 Iterator<String>。main方法實例化了它,然后進行迭代。 > The type MyStringIterator in this example quali?es as iterator: It de?nes a method hasNext returning Bool and a method next returning String, making it compatible with Iterator<String>. The main method instantiates it, then iterates over it. ~~~ class MyArrayWrap<T> { var a:Array<T>; public function new(a:Array<T>) { this.a = a; } public function iterator() { return a.iterator(); } } class Main { static public function main() { var myWrap = new MyArrayWrap([1, 2, 3]); for (elt in myWrap) { trace(elt); } } } ~~~ 這里我們沒有設置一個像上利中完整的迭代器,而是定義MyArrayWrap<T> 有一個方法 iterator ,有效的轉發包裝的Array<T>類型的iterator方法。 > Here we do not setup a full iterator like in the previous example, but instead de?ne that the MyArrayWrap<T> has a method iterator, effectively forwarding the iterator method of the wrapped Array<T> type.
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看