Skip to content

What I Learned Today

Inspired by this post.

A nice Groovy snippet:

def x = [a: 1, b: 2]
def y = [x: 'hi', y: 'there']
def z = [groovy: 'is', good: 'stuff']

def e = new Expando(*:x, *:y, *:z)

println e

Running within GroovyConsole produces:

groovy> def x = [a: 1, b: 2]
groovy> def y = [x: 'hi', y: 'there']
groovy> def z = [groovy: 'is', good: 'stuff']
groovy> def e = new Expando(*:x, *:y, *:z)
groovy> println e

{a=1, b=2, x=hi, y=there, groovy=is, good=stuff}

There are more good examples hidden away in the documentation on Groovy Maps.

And while I’m at it…I’ll preserve this bit of List-y goodness (a Bob ‘original’) for posterity (otherwise it will get lost in the depths of my email, never to be seen again):

[-90.0F, 0.0F, (25.0F..45.0F).findAll { it % 5.0F == 0.0F }, 90.0F].flatten().each { deg ->
  println deg
}

Produces:

-90.0
0.0
25.0
30.0
35.0
40.0
45.0
90.0

[edit]
I found an even simpler way:

[-90.0F, 0.0F, (25.0F..45.0F).step(5), 90.0F].flatten().each { deg ->
  println deg
}

It’s a shame that step() only takes an integer parameter, but that is OK for this case.

Tags:

Java Enterprise Edition, JEE, JavaServer Pages, JSP, Tag Libraries, Servlets, Enterprise Java Beans, EJB, Java Messaging Service JMS, BEA Weblogic, JBoss, Application Servers, Spring Framework, Groovy, Grails, Griffon, Seam, Open Source, Service Oriented Architectures, SOA, Java 2 Standard Edition, J2SE