One thing I only recently learned about Groovy is that by implementing the getAt method, you can destructure your Object via multiple assignment.
As an example, consider a class Vector2D which represents a two-dimensional vector:
Last night, I saw a post on my twitter feed titled “Why Functional Programming in Java is Dangerous” where the author tries to implement the clojure code
in a functional style in Java, then concludes that “Functional idioms in Java are performance bugs waiting to bite you” after trying to load all of the Integers Java can handle into an ArrayList.
Buoyed by my success pushing the groovy-common-extensions library to maven, I pushed the groovy-stream library to maven as well, so it’s now possible (without any messing around with @GrabResolver) to give the library a whirl.
Last week I pushed my groovy-common-extensions project to maven via sonatype using the brilliant Gradle Nexus plugin by @bmuschko
A quick note to myself. I found a bug in Groovy 2.0.5 that prevented you having an Immutable class that contained one of either Clojure’s PersistentList and PersistentVector.
The bug was fixed for Groovy 2.0.6, and I just tested it and it all works great (thanks Paul for the fix)
This Christmas, I received a Raspberry Pi from Santa, so thought I’d have a go at getting JavaFX running on it. Of course, due to my interest in all things Groovy, I decided to go straight for getting GroovyFX running. After a day or two of foozling around (and at least half a day getting distracted by the RASPBMC media centre), I succeeded so thought I would post the steps I took here so others can follow my path to GroovyFX happiness.
One of the things I love about how Groovy is built, is that quite a few of the examples in the Javadoc are automatically tested when you run ./gradlew test
The beauty of this is that the examples you show the user in the documentation are guaranteed to work. No more out of date, flakey examples. And no more having to search the source with your fingers crossed there are Unit Tests, or searching the site for any sort of documentation.
Saw a tweet from Rob Fletcher about the 99 bottles of beer song written in LOLcode
99 Bottles of Beer in #LOLCODE 99-bottles-of-beer.net/language-lolco… #nextbiglanguage /via @cressie176
— Rob Fletcher (@rfletcherEW) December 6, 2012
And decided to see what it would look like with a groovy-stream.
This is what I ended up with:
If you’ve written a web-app you’ve undoubtedly hit the issue of people pasting text in from Microsoft Word. The problem here is that Word converts characters into other symbols to improve the typography, and this sometimes ends up with issues when you try and save the text into a database, or simply display it back to the user.
Lately I’ve been interested in core.logic, a Clojure library written by David Nolen that implements miniKanren in Clojure.
Today, I came across an old blog post by Ryan Senior with a cool example for describing family trees in The Godfather, and I wondered if it was possible to embed this code in a Groovy script so that we could pass a parameter into core.logic, and get the results back into Groovy.