1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Haxe 内包表記内で複数の式や文を使う書き方

Last updated at Posted at 2013-11-12

HaxeではPythonとかHaskellみたいな感じで、配列内包表記が使えます。

そこんところ一時変数の束縛とかしたいなーとか思ったので以下みたいな感じに。
早い話が即時関数を作ってやれば良いかんじ。

class Main {

    public static function main() {
        var fizz_buzz =
                [for (_i in 0...100)
                    function(i) {
                        trace(i);
                        return
                            switch (i) {
                                case 0: '0';
                                case i if (i % 15 == 0): 'fizz buzz';
                                case i if (i % 3 == 0): 'fizz';
                                case i if (i % 15 == 0): 'buzz';
                                case i: Std.string(i);
                            }
                    }(_i)
                ];
        trace(fizz_buzz);
    }
}

fizzbuzzならいらないじゃんとか思って、無意味にtraceはさんでるアレ。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?