Groovy for Domain-specific Languages - Second Edition
The Groovy Language [ 78 ] Range objects have two properties, to and from, that define their limits, as shown in the following c ...
Chapter 4 [ 79 ] [1,3,5] + [["apple","orange","pear"]] == multidimensional and: "also with the left shift operator" [1,3,5] < ...
The Groovy Language [ 80 ] Groovy adds two additional new methods to lists: any and every. These return a Boolean value if any o ...
Chapter 4 [ 81 ] When assigning values to Map elements, we can use either the array superscript syntax or property access syntax ...
The Groovy Language [ 82 ] We also can use object values as keys, but in order to do so, we need to add parentheses around them ...
Chapter 4 [ 83 ] given: "An array of Name objects" def names = [ new Name(name:"Aaron"), new Name(name:"Bruce"), new Name(name:" ...
The Groovy Language [ 84 ] Operator overloading Java inherited many features from the C++ language, with one notable exception— ...
[ 85 ] Groovy Closures In this chapter, we will focus exclusively on closures. We touched upon closures already in the previous ...
Groovy Closures [ 86 ] What is a closure? Closures are such an unfamiliar concept to begin with that it can be hard to grasp ini ...
Chapter 5 [ 87 ] Closures and collection methods In the last chapter, we encountered Groovy lists and saw some of the iteration ...
Groovy Closures [ 88 ] The java.lang.Object class has a number of similar methods such as each, find, every, any, and so on. Bec ...
Chapter 5 [ 89 ] Groovy has special handling for methods whose last parameter is a closure. When invoking these methods, the clo ...
Groovy Closures [ 90 ] The effect of this is that whenever we need to execute a locked segment of code, we simply wrap the segme ...
Chapter 5 [ 91 ] when: "we invoke a method that accepts a String and a Closure" closureMethodString("Dolly") { name -> printl ...
Groovy Closures [ 92 ] At this point, we can write code that nests the two method calls by calling update as follows: locked { u ...
Chapter 5 [ 93 ] } } ) CThread down = new CThread( { ["three","two", "one", "liftoff"] each { sleep(100) println it } } ) Here w ...
Groovy Closures [ 94 ] The implicit doCall method There is a third mechanism that you can use to invoke a Closure calling the do ...
Chapter 5 [ 95 ] We can then make use of this closure class in our Groovy code as normal. Groovy will match closure invocations ...
Groovy Closures [ 96 ] We can implement a login action for our user controller in Grails—simply by declaring a closure in the co ...
Chapter 5 [ 97 ] Closure parameters In our previous examples, we have made use of the it keyword. When a closure accepts only a ...
«
1
2
3
4
5
6
7
8
9
10
»
Free download pdf