<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之旅 廣告
                Lambda 類包含一些方法來以函數式編程風格的方式修改數組和迭代器的內容。很大程度上,多數方法只是在你之前看到的一些局部方法上的一些變化,不同的是,它們比之前看到的影響不同的集合。 Lambda類提供如下方法: |Lambda方法|描述| | -- | -- | |array< A >(it:Iterable< A >):Array< A >|從Iterable< A >創建 Array< A > ,返回Iterable< A >中元素數量| |count< A >(it: Iterable< A >):Int|返回Iterable< A >中元素數量| |empty(it: Iterable< Dynamic >):Bool|驗證一個可迭代對象是否不包含任何元素| |exists< A >(it: Iterable< A >, f:A->Bool):Bool|是否至少有一個迭代元素的對象通過指定函數被找到| |filter< A >(it:Iterable< A >,f:A->Bool):List< A >|返回符合指定函數的元素列表| |fold(A,B)(it:Iterable< A >,f:A->B->B, first:B):B|在Iterator< A >上執行fold(折疊)功能| |foreach< A >(it:Iterable< A >,f:A->Bool):Bool|是否所有迭代對象的元素有f指定的屬性| |has< A >(it:Iterable< A >, elt:A,?cmp:A->A->Bool):Bool|是否某個元素是迭代對象的部分| |iter< A >(it:Iterable< A >,f:A->Void):Void|應用函數到Iterable< A >的每個元素| |list< A >(it:Iterable< A >):List< A >|從Iterable< A >創建一個List| |map< A,B >(it:Iterable< A >, f:A->B):List< B >|通過應用指定函數從Iterable< A >創建一個Iterable< B >| |mapi< a,b >(it:Iterable< A >,f:Int->A->B):List< B >|和map類似,但是同時會傳遞每個迭代項的索引| # map() 和 mapi() * * * * * map 和 mapi 方法和List集合的map方法非常相似,不同的是Lambda.map 接收一個迭代器作為第一個參數,返回一個新的迭代器,而Lambda.mapi 執行相同的功能,還傳遞一個索引到處理函數。這里是兩個方法的例子: ~~~ class Mapping { public static function main() { var myArr : Array < Int > = [1, 2, 3, 4]; var newIter : Iterator < Int > ; var funIter = function( x : Int ) : Int { return x * 2; } newIter = Lambda.map( myArr, funIter ); // Outputs: 2, 4, 6, 8 for ( i in newIter ) trace( i ); } } ~~~ # array() 和 list() * * * * * 從一個Array或者List創建迭代器很簡單,因為它們都暴露了 iterator() 方法。然而,從迭代器創建一個List或者Array 呢?這正是 Lambda.array() 和Lambda.list() 做的。其中最大的好處是,它們可以非常快速和簡單的轉換一個 Array 到一個 List ,通過這些代理方法反之亦然: ~~~ var myArr : Array < Int > = [ 1, 2, 3, 4 ]; // Creates the List from the Array var myLst : List < Int > = Lambda.list( myArr ); // Recreates the Array from the List myArr = Lambda.array( myLst ); ~~~ # fold() * * * * * fold 函數非常有用,因為它會使你從一個迭代器應用一個接收每個元素并返回一個基于和開始值計算得出的值的函數生成一個值。這個值然后被帶入下一個計算調用下一個迭代器中的值。例如,你傳遞 fold 函數一個迭代器包含一個整數的列表,一個開始的整數值,和一個帶入兩個整數并對齊相加的函數。結果就是迭代中所有項相加的和加上開始的整數值: ~~~ class FoldList { public static function main() { var arr : Array < Int > = [1,2,3,4,5]; var fun : Int - > Int - > Int = function( a : Int, b : Int ) : Int { return a + b; } var initialValue : Int = 22; // Outputs: 37 trace(Lambda.fold(arr, fun, initialValue)); } } ~~~
                  <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>

                              哎呀哎呀视频在线观看