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
| Modifier and Type | Field and Description |
|---|---|
| private Closure | |
| private Closure | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public V | call(Object... args)
Overrides groovy. |
| public Object | |
| public Object | |
| public Object | |
| public Class | |
| public int | getResolveStrategy()
Overrides groovy. |
| public void | setDelegate(Object
the new delegate delegate)Overrides groovy. |
| public void | setResolveStrategy(int
The resolve strategy to set resolveStrategy)Overrides groovy. |
| first | back to summary |
|---|---|
| private Closure<V> first | |
| second | back to summary |
|---|---|
| private Closure<V> second | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| ComposedClosure | back to summary |
|---|---|
| public ComposedClosure(Closure<V> first, Closure<V> second) | |
| call | back to summary |
|---|---|
| public V call(Object... args) Overrides groovy. Doc from groovy. Invokes the closure with given argument(s), returning any value if applicable.
| |
| 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
| |
| doCall | back to summary |
|---|---|
| public Object doCall(Object... args) | |
| 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
| |
| 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
| |