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

public final Class ComposedClosure<V>

extends Closure<V>
Class Inheritance
Imports
groovy.lang.Closure, java.util.List

A wrapper for Closure to support composition. Normally used only internally through the rightShift() and leftShift() methods on Closure.

Typical usages:

def twice = { a -> a * 2 }
def inc = { b -> b + 1 }
def f = { x -> twice(inc(x)) } // longhand
def g = inc >> twice
def h = twice << inc
assert f(10) == 22
assert g(10) == 22
assert h(10) == 22

def s2c = { it.chars[0] }
def p = Integer.&toHexString >> s2c >> Character.&toUpperCase
assert p(15) == 'F'

def multiply = { a, b -> a * b }
def identity = { a -> [a, a] }
def sq = identity >> multiply
assert (1..5).collect{ sq(it) } == [1, 4, 9, 16, 25]

def add3 = { a, b, c -> a + b + c }
def add2plus10 = add3.curry(10)
def multBoth = { a, b, c -> [a*c, b*c] }
def twiceBoth = multBoth.rcurry(2)
def twiceBothPlus10 = twiceBoth >> add2plus10
assert twiceBothPlus10(5, 10) == 40

Field Summary

Modifier and TypeField and Description
private Closure<V>
private Closure<V>
private static final long
Inherited from groovy.lang.Closure:
DELEGATE_FIRSTDELEGATE_ONLYDONEIDENTITYmaximumNumberOfParametersOWNER_FIRSTOWNER_ONLYparameterTypesSKIPTO_SELF

Constructor Summary

AccessConstructor and Description
public
ComposedClosure(Closure<V> first, Closure<V> second)

Method Summary

Modifier and TypeMethod and Description
public V
call(Object... args)

Overrides groovy.lang.Closure.call.

Invokes the closure with given argument(s), returning any value if applicable.
public Object
clone()

Overrides groovy.lang.Closure.clone.

Creates and returns a copy of this object.
public Object
doCall(Object... args)

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 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:
andThenandThenSelfandThenSelfasWritablecallcallcomposecomposeSelfcomposeSelfcurrycurrydehydrategetDirectivegetMaximumNumberOfParametersgetOwnergetPropertygetThisObjectisCaseleftShiftleftShiftmemoizememoizeAtLeastmemoizeAtMostmemoizeBetweenncurryncurryrcurryrcurryrehydraterightShiftrunsetDirectivesetPropertythrowRuntimeExceptiontrampolinetrampoline

Field Detail

firstback to summary
private Closure<V> first
secondback to summary
private Closure<V> second
serialVersionUIDback to summary
private static final long serialVersionUID

Hides groovy.lang.Closure.serialVersionUID.

Constructor Detail

ComposedClosureback to summary
public ComposedClosure(Closure<V> first, Closure<V> second)

Method Detail

callback to summary
public V call(Object... args)

Overrides groovy.lang.Closure.call.

Doc from groovy.lang.Closure.call.

Invokes the closure with given argument(s), returning any value if applicable.

Returns:V

The value if applicable or null if there is no return statement in the closure.

Annotations
@Override
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.

doCallback to summary
public Object doCall(Object... args)
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

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