fork download
  1. def print_args(f) { { Object... args -> args.each { println it }; f(*args) } }
  2.  
  3. def add = { x, y -> x + y }
  4.  
  5. def sum = { x -> x.inject { acc, val -> acc + val } }
  6.  
  7. println add(1,2)
  8. def print_args_add = print_args(add)
  9. println print_args_add(1,2)
  10.  
  11. println sum([1,2])
  12. def print_args_sum = print_args(sum)
  13. println print_args_sum([1,2])
  14.  
  15. Object x = new Object[2]
  16. x[0] = 1
  17. x[1] = 2
  18.  
  19. println sum(x)
  20. println print_args_sum(x)
Runtime error #stdin #stdout #stderr 1.4s 388352KB
stdin
Standard input is empty
stdout
3
1
2
3
3
[1, 2]
3
3
1
2
stderr
Caught: groovy.lang.MissingMethodException: No signature of method: prog$_run_closure2.call() is applicable for argument types: (java.lang.Integer, java.lang.Integer) values: [1, 2]
Possible solutions: any(), any(), find(), collect(), dump(), grep()
groovy.lang.MissingMethodException: No signature of method: prog$_run_closure2.call() is applicable for argument types: (java.lang.Integer, java.lang.Integer) values: [1, 2]
Possible solutions: any(), any(), find(), collect(), dump(), grep()
	at prog$_print_args_closure3.doCall(prog.groovy:1)
	at prog.run(prog.groovy:20)