View Javadoc

    1
    2   package org.codehaus.groovy.runtime;
    3
    4
    5   import groovy.lang.Closure;
    6
    7   /***
    8    * Represents wrapper around a Closure to support currying
    9    *
    10   * @author Jochen Theodorou
    11   */
    12  public class CurriedClosure extends Closure {
    13
    14      private Object[] curriedParams;
    15
    16      public CurriedClosure(Closure uncurriedClosure, Object[] arguments) {
    17          super(uncurriedClosure);
    18          curriedParams = arguments;
    19          maximumNumberOfParameters = uncurriedClosure.getMaximumNumberOfParameters()-arguments.length;
    20      }
    21
    22      public Object[] getUncurriedArguments(Object[] arguments) {
    23          final Object newCurriedParams[] = new Object[curriedParams.length + arguments.length];
    24          System.arraycopy(curriedParams, 0, newCurriedParams, 0, curriedParams.length);
    25          System.arraycopy(arguments, 0, newCurriedParams, curriedParams.length, arguments.length);
    26          return newCurriedParams;
    27      }
    28
    29  }