BoolexprUtils

Codes & Snippets

9 years
edited 8 years
True and False BooleanExpressions

Credits goes to Vexorian for the first idea.


Vjass version
Code (jass) Select
library BoolexprUtils

    globals
        boolexpr BOOLEXPR_TRUE
        boolexpr BOOLEXPR_FALSE
    endglobals

    private module Init

        private static method filterTrue takes nothing returns boolean
            return true
        endmethod

        private static method filterFalse takes nothing returns boolean
            return false
        endmethod

        private static method onInit takes nothing returns nothing
            set BOOLEXPR_TRUE = Filter(function thistype.filterTrue)
            set BOOLEXPR_TRUE = Filter(function thistype.filterFalse)
        endmethod

    endmodule

    private struct S extends array
        implement Init
    endstruct

endlibrary


Zinc version
Code (jass) Select
//! zinc
library BoolexprUtils {

    public boolexpr BOOLEXPR_TRUE, BOOLEXPR_FALSE;

    module Init {
        static method onInit() {
            BOOLEXPR_TRUE = Filter(function() -> boolean {return true;});
            BOOLEXPR_FALSE = Filter(function() -> boolean {return false;});
        }
    }

    struct S extends array {module Init;}

}
//! endzinc
9 years
simple, but effective ;)

Good job!