<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 3.1.0以后** > **Since Haxe 3.1.0** 提取器允許應用變換到被匹配的值。這才需要對一個匹配的值在匹配繼續之前做一個小的操作時經常用到: > Extractors allow applying transformations to values being matched. This is often useful when a small operation is required on a matched value before matching can continue: ~~~ enum Test { TString(s:String); TInt(i:Int); } class Main { static public function main() { var e = TString("fOo"); switch(e) { case TString(temp): switch(temp.toLowerCase()) { case "foo": true; case _: false; } case _: false; } } } ~~~ 這里我們需要TString 枚舉構造器的參數值到一個變量 temp,并使用一個嵌套的 switch到temp.toLowerCase() 。很明顯,我們想要匹配如果TString保存一個無論大小寫的“foo”則成功。這可以通過提取器簡單實現: > Here we have to capture the argument value of the TString enum constructor in a variable temp and use a nested switch on temp.toLowerCase(). Obviously, we want matching to succeed if TString holds a value of "foo" regardless of its casing. This can be simpli?ed with extractors: ~~~ enum Test { TString(s:String); TInt(i:Int); } class Main { static public function main() { var e = TString("fOo"); var success = switch(e) { case TString(_.toLowerCase() => "foo"): true; case _: false; } } } ~~~ 提取器通過extractorExpression => match 表達式識別。編譯器生成的代碼類似于前面的例子,但是原生的語法被大大精簡。提取器由兩部分組成,被 => 操作符分隔: > Extractors are identi?ed by the extractorExpression => match expression. The compiler generates code which is similar to the previous example,but the original syntax was greatly simpli?ed. Extractors consist of two parts, which are separated by the => operator: * 左側可以使任何的表達式,中間出現的所有下劃線被替換為當前匹配的值。 * 右側是一個模式,匹配的左側執行的結果。 > * The left side can be any expression,where all occurrences of underscore_are replaced with the currently matched value. > * The right side is a pattern which is matched against the result of the evaluation of the left side. 因為右側是模式,它可以包含另外的提取器。下面的例子鏈接了兩個提取器: > Since the right side is a pattern, it can contain another extractor. The following example “chains” two extractors: ~~~ class Main { static public function main() { switch(3) { case add(_, 1) => mul(_, 3) => a: trace(a); } } static function add(i1:Int, i2:Int) { return i1 + i2; } static function mul(i1:Int, i2:Int) { return i1 * i2; } } ~~~ 這里輸出 12 作為調用 add(3,1)的結果,3是匹配的值,mul(4,3)中4是add調用的結果。需要注意的是,a在第二個 =>操作符的右側是一個捕獲的變量(第6.4.3節)。 > This traces 12 as a result of the calls to add(3, 1), where 3 is the matched value, and mul(4, 3) where 4 is the result of the add call. It is worth noting that the a on the right side of the second => operator is a capture variable (6.4.3). 當前不能在 or 模式中使用提取器: > It is currently not possible to use extractors within or-patterns (6.4.6): ~~~ class Main { static public function main() { switch("foo") { // Extractors in or patterns are not allowed case (_.toLowerCase() => "foo") | "bar": } } } ~~~ 然而,可以把or模式用在提取器的右側,所以前面的例子會編譯而沒有括號。 > However, it is possible to have or-patterns on the right side of an extractor, so the previous example would compile without the parentheses.
                  <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>

                              哎呀哎呀视频在线观看