Top Description Fields Constructors Methods
org.codehaus.groovy.runtime

public final Class CurriedClosure<V>

extends Closure<V>
Class Inheritance
Imports
groovy.lang.Closure

A wrapper for Closure to support currying. Normally used only internally through the 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:

Field Summary

Modifier and TypeField and Description
private final Object[]
private int
private final int
private static final long
private Class<T>
Inherited from groovy.lang.Closure:
DELEGATE_FIRSTDELEGATE_ONLYDONEIDENTITYmaximumNumberOfParametersOWNER_FIRSTOWNER_ONLYparameterTypesSKIPTO_SELF

Constructor Summary

AccessConstructor 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
CurriedClosure(Closure<V> uncurriedClosure, Object... arguments)

Method Summary

Modifier and TypeMethod and Description
public Object
clone()

Overrides groovy.lang.Closure.clone.

Creates and returns a copy of this object.
private Object[]
createNewCurriedParams(int normalizedIndex, Object[] arguments)

public Object
public Class<T>[]
public int
getResolveStrategy()

Overrides groovy.lang.Closure.getResolveStrategy.

Gets the strategy which the closure uses to resolve methods and properties
public Object[]
private boolean
public void
setDelegate(Object
the new delegate
delegate
)

Overrides groovy.lang.Closure.setDelegate.

Allows the delegate to be changed such as when performing markup building
public void
setResolveStrategy(int
The resolve strategy to set
resolveStrategy
)

Overrides groovy.lang.Closure.setResolveStrategy.

Sets the strategy which the closure uses to resolve property references and methods.
Inherited from groovy.lang.Closure:
andThenandThenSelfandThenSelfasWritablecallcallcallcomposecomposeSelfcomposeSelfcurrycurrydehydrategetDirectivegetMaximumNumberOfParametersgetOwnergetPropertygetThisObjectisCaseleftShiftleftShiftmemoizememoizeAtLeastmemoizeAtMostmemoizeBetweenncurryncurryrcurryrcurryrehydraterightShiftrunsetDirectivesetPropertythrowRuntimeExceptiontrampolinetrampoline

Field Detail

curriedParamsback to summary
private final Object[] curriedParams
indexback to summary
private int index
minParamsExpectedback to summary
private final int minParamsExpected
serialVersionUIDback to summary
private static final long serialVersionUID

Hides groovy.lang.Closure.serialVersionUID.

varargTypeback to summary
private Class<T> varargType

Constructor Detail

CurriedClosureback to summary
public CurriedClosure(int index, Closure<V> uncurriedClosure, Object... arguments)

Creates the curried closure.

Parameters
index:int

the position where the parameters should be injected (-ve for lazy)

uncurriedClosure:Closure<V>

the closure to be called after the curried parameters are injected

arguments:Object[]

the supplied parameters

CurriedClosureback to summary
public CurriedClosure(Closure<V> uncurriedClosure, Object... arguments)

Method Detail

cloneback to summary
public Object clone()

Overrides groovy.lang.Closure.clone.

Doc from java.lang.Object.clone.

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 x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

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 super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

Returns:Object

a clone of this instance.

Annotations
@SuppressWarnings:unchecked
createNewCurriedParamsback to summary
private Object[] createNewCurriedParams(int normalizedIndex, Object[] arguments)
getDelegateback to summary
public Object getDelegate()

Overrides groovy.lang.Closure.getDelegate.

Returns:Object

Doc from groovy.lang.Closure.getDelegate.

the delegate Object to which method calls will go which is typically the outer class when the closure is constructed

getParameterTypesback to summary
public Class<T>[] getParameterTypes()

Overrides groovy.lang.Closure.getParameterTypes.

Returns:Class<T>[]

Doc from groovy.lang.Closure.getParameterTypes.

the parameter types of the longest doCall method of this closure

getResolveStrategyback to summary
public int getResolveStrategy()

Overrides groovy.lang.Closure.getResolveStrategy.

Doc from groovy.lang.Closure.getResolveStrategy.

Gets the strategy which the closure uses to resolve methods and properties

Returns:int

The resolve strategy

getUncurriedArgumentsback to summary
public Object[] getUncurriedArguments(Object... arguments)
isVarargback to summary
private boolean isVararg()
setDelegateback to summary
public void setDelegate(Object delegate)

Overrides groovy.lang.Closure.setDelegate.

Doc from groovy.lang.Closure.setDelegate.

Allows the delegate to be changed such as when performing markup building

Parameters
delegate:Object

the new delegate

setResolveStrategyback to summary
public void setResolveStrategy(int resolveStrategy)

Overrides groovy.lang.Closure.setResolveStrategy.

Doc from groovy.lang.Closure.setResolveStrategy.

Sets the strategy which the closure uses to resolve property references and methods. The default is Closure.OWNER_FIRST

Parameters
resolveStrategy:int

The resolve strategy to set