A equipe do Groovy anunciou o lançamento de mais duas releases da linguagem, destacando principalmente dois recursos: "closure composition" e "the new extended DSL capabilities".
Both releases contain several bug fixes and minor improvements, but I’d particularly like to highlight two new features of Groovy 1.8-beta-2: closure composition and the new extended DSL capabilities. Make sure to have a look at the new features from the previous beta of 1.8 too, if you haven’t had a chance so far.
If you recall your math lessons, function composition may be a concept you’re familiar with. And in turn, closure composition is about that: the ability to compose closures together to form a new closure which chains the call of those closures. Here’s an example of composition in action:
def plus2 = { it + 2 }
def times3 = { it * 3 }
def composed1 = plus2 << times3
assert composed1(3) == 11
assert composed1(4) == plus2(times3(4))
def composed2 = times3 << plus2
assert composed2(3) == 15
assert composed2(5) == times3(plus2(5))
// reverse composition
assert composed1(3) == (times3 >> plus2)(3)
To see more examples of closure composition and reverse composition, please have a look at our test case.
Groovy 1.8-beta-2 features the great work of our Google Summer of Code student, Lidia Donajczyk, who worked on an extension of the command expression notation (also known as GEP-3 / Extended Command Expressions). In a nutshell, Groovy allows you to omit dots and parentheses for chained methods calls, so that such calls look more like natural language sentences.
A few sentences this new DSL capability will allow you to write:
move left by 30.centimeters
sell 100.shares of MSFT
take 2.pills of chloroquinine in 6.hours
[url=http://jira.codehaus.org/secure/ReleaseNote.jspa?projectId=10242&version=16639]* JIRA release notes for Groovy 1.7.5[/url]
[url=http://jira.codehaus.org/secure/ReleaseNote.jspa?projectId=10242&version=16629]* JIRA release notes for Groovy 1.8-beta-2[/url]
É isso aí! Agora nos resta explorar os novos recursos!
Até a próxima!