Search code examples
haxe

Check equaling enum without parameter


I use enums but can't find good way to check eqauling.

enum Turn {
    A(value:Int);
    B(value:Int);
}
class Test {
    static function main() {
        var turn = Turn.A(100);
        //I want to Check turn is Turn.A(any value) without using 'switch'.
        if (turn == Turn.A) ...
    }
}

Is there any good and simple way to checking?


Solution

  • You can use the .match() function:

    if (turn.match(Turn.A(_)))