Sha256: 84634edff325237e569e2eb5361ca70905052b7957e5b392e65b4d2a2a21862f

Contents?: true

Size: 1.05 KB

Versions: 17

Compression:

Stored size: 1.05 KB

Contents

//http://groovy.codehaus.org/Martin+Fowler%27s+closure+examples+in+Groovy

class Employee {
    def name, salary
    boolean manager
    String toString() { return name }
}

def emps = [new Employee(name:'Guillaume', manager:true, salary:200),
    new Employee(name:'Graeme', manager:true, salary:200),
    new Employee(name:'Dierk', manager:false, salary:151),
    new Employee(name:'Bernd', manager:false, salary:50)]

def managers(emps) {
    emps.findAll { e -> e.isManager() }
}

assert emps[0..1] == managers(emps) // [Guillaume, Graeme]

def highPaid(emps) {
    threshold = 150
    emps.findAll { e -> e.salary > threshold }
}

assert emps[0..2] == highPaid(emps) // [Guillaume, Graeme, Dierk]

def paidMore(amount) {
    { e -> e.salary > amount}
}
def highPaid = paidMore(150)

assert highPaid(emps[0]) // true
assert emps[0..2] == emps.findAll(highPaid)

def filename = 'test.txt'
new File(filename).withReader{ reader -> doSomethingWith(reader) }

def readersText
def doSomethingWith(reader) { readersText = reader.text }

assert new File(filename).text == readersText

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
agile-proxy-0.1.24 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/groovy.groovy
agile-proxy-0.1.23 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/groovy.groovy
agile-proxy-0.1.22 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/groovy.groovy
agile-proxy-0.1.21 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/groovy.groovy
agile-proxy-0.1.20 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/groovy.groovy
agile-proxy-0.1.19 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/groovy.groovy
agile-proxy-0.1.18 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/groovy.groovy
agile-proxy-0.1.13 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/groovy.groovy
agile-proxy-0.1.12 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/groovy.groovy
agile-proxy-0.1.11 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/groovy.groovy
agile-proxy-0.1.10 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/groovy.groovy
agile-proxy-0.1.9 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/groovy.groovy
agile-proxy-0.1.8 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/groovy.groovy
agile-proxy-0.1.7 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/groovy.groovy
agile-proxy-0.1.6 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/groovy.groovy
agile-proxy-0.1.5 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/groovy.groovy
agile-proxy-0.1.4 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/groovy.groovy