Groovy web console

subscribe to the feed Subscribe
to this
Composition doesnt bind delegation (via #groovywebconsole)
tweet this snippet Tweet

Composition doesnt bind delegation

Published 6 years ago by jneira with tags closure composition delegate
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
class CriteriaBuilder {
  def eq(property,value) {println "${property} = ${value}"}
  def 'in'(property,list) {println "${property} in ${list}"}

def criterio1= {eq("prop1",1)}
def criterio2= {'in'("prop2",[1,2,3])}

def composition=criterio1 >> criterio2

def c=new CriteriaBuilder()
c.with criterio1
// prop1 = 1
c.with criterio2
// prop2 in [1, 2, 3]
c.with composition
// groovy.lang.MissingMethodException: No signature of method: Script1.eq() is applicable