Main.hx 774 B

12345678910111213141516171819202122232425262728293031323334
  1. interface MathOperation {
  2. function perform(a:Int, b:Int):Int;
  3. }
  4. class Ops {
  5. static public final add:MathOperation = (a, b) -> a + b;
  6. static public final subtract:MathOperation = (a, b) -> a - b;
  7. static public function performMathOperation(operation:MathOperation) {
  8. return operation.perform(8, 4);
  9. }
  10. }
  11. class Main {
  12. static function main() {
  13. var result = Ops.performMathOperation(Ops.add);
  14. trace('Add: ${result}');
  15. result = Ops.performMathOperation(Ops.subtract);
  16. trace('Subtract: ${result}');
  17. result = Ops.performMathOperation(multiply);
  18. trace('Multiply: ${result}');
  19. result = Ops.performMathOperation(function(a, b):Int {
  20. return Std.int(a / b);
  21. });
  22. trace('Divide: ${result}');
  23. }
  24. static function multiply(a, b):Int {
  25. return a * b;
  26. }
  27. }