curry(), rcurry() or
ncurry() methods on Closure.
Typical usages:
// normal usage
def unitAdder = { first, second, unit -> "${first + second} $unit" }
assert unitAdder(10, 15, "minutes") == "25 minutes"
assert unitAdder.curry(60)(15, "minutes") == "75 minutes"
def minuteAdder = unitAdder.rcurry("minutes")
assert minuteAdder(15, 60) == "75 minutes"
// explicit creation
import org.codehaus.groovy.runtime.CurriedClosure
assert new CurriedClosure(unitAdder, 45)(15, "minutes") == "60 minutes"
assert new CurriedClosure(unitAdder, "six", "ty")("minutes") == "sixty minutes"
Notes:
| Modifier and Type | Field and Description |
|---|---|
| private final Object[] | |
| private int | |
| private final int | |
| private static final long | |
| private Class |
| Access | Constructor and Description |
|---|---|
| public | CurriedClosure(int
the position where the parameters should be injected (-ve for lazy) index, Closure<V> the closure to be called after the curried parameters are injected uncurriedClosure, Object... the supplied parameters arguments)Creates the curried closure. |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Object | |
| private Object[] | |
| public Object | |
| public Class | |
| public int | getResolveStrategy()
Overrides groovy. |
| public Object[] | |
| private boolean | |
| public void | setDelegate(Object
the new delegate delegate)Overrides groovy. |
| public void | setResolveStrategy(int
The resolve strategy to set resolveStrategy)Overrides groovy. |
| curriedParams | back to summary |
|---|---|
| private final Object[] curriedParams | |
| index | back to summary |
|---|---|
| private int index | |
| minParamsExpected | back to summary |
|---|---|
| private final int minParamsExpected | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| varargType | back to summary |
|---|---|
| private Class<T> varargType | |
| CurriedClosure | back to summary |
|---|---|
| public CurriedClosure(int index, Closure<V> uncurriedClosure, Object... arguments) Creates the curried closure. | |
| CurriedClosure | back to summary |
|---|---|
| public CurriedClosure(Closure<V> uncurriedClosure, Object... arguments) | |
| clone | back to summary |
|---|---|
| public Object clone() Overrides groovy. Doc from java. Creates and returns a copy of this object. The precise meaning
of "copy" may depend on the class of the object. The general
intent is that, for any object will be true, and that the expression:x.clone() != x will bex.clone().getClass() == x.getClass() true, but these are not absolute requirements.
While it is typically the case that:
will bex.clone().equals(x) true, this is not an absolute requirement.
By convention, the returned object should be obtained by calling
By convention, the object returned by this method should be independent
of this object (which is being cloned). To achieve this independence,
it may be necessary to modify one or more fields of the object returned
by
| |
| createNewCurriedParams | back to summary |
|---|---|
| private Object[] createNewCurriedParams(int normalizedIndex, Object[] arguments) | |
| getDelegate | back to summary |
|---|---|
| public Object getDelegate() Overrides groovy.
| |
| getParameterTypes | back to summary |
|---|---|
| public Class Overrides groovy.
| |
| getResolveStrategy | back to summary |
|---|---|
| public int getResolveStrategy() Overrides groovy. Doc from groovy. Gets the strategy which the closure uses to resolve methods and properties
| |
| getUncurriedArguments | back to summary |
|---|---|
| public Object[] getUncurriedArguments(Object... arguments) | |
| isVararg | back to summary |
|---|---|
| private boolean isVararg() | |
| setDelegate | back to summary |
|---|---|
| public void setDelegate(Object delegate) Overrides groovy. Doc from groovy. Allows the delegate to be changed such as when performing markup building
| |
| setResolveStrategy | back to summary |
|---|---|
| public void setResolveStrategy(int resolveStrategy) Overrides groovy. Doc from groovy. Sets the strategy which the closure uses to resolve property references and methods. The default is Closure.OWNER_FIRST
| |