01: package org.codehaus.groovy.runtime;
02:
03: import groovy.lang.Closure;
04:
05: /**
06: * Represents wrapper around a Closure to support currying
07: *
08: * @author Jochen Theodorou
09: */
10: public class CurriedClosure extends Closure {
11:
12: private Object[] curriedParams;
13:
14: public CurriedClosure(Closure uncurriedClosure, Object[] arguments) {
15: super (uncurriedClosure);
16: curriedParams = arguments;
17: maximumNumberOfParameters = uncurriedClosure
18: .getMaximumNumberOfParameters()
19: - arguments.length;
20: }
21:
22: public Object[] getUncurriedArguments(Object[] arguments) {
23: final Object newCurriedParams[] = new Object[curriedParams.length
24: + arguments.length];
25: System.arraycopy(curriedParams, 0, newCurriedParams, 0,
26: curriedParams.length);
27: System.arraycopy(arguments, 0, newCurriedParams,
28: curriedParams.length, arguments.length);
29: return newCurriedParams;
30: }
31:
32: }
|