groovy

Groovy code golfing

Introduction#

Tips for golfing in Groovy

Spread dot operator(*.)

Spread dot operator can be used instead of collect method

(1..10)*.multiply(2) // equivalent to (1..10).collect{ it *2 }
d = ["hello", "world"]
d*.size() // d.collect{ it.size() }

Parallel processing using Gpars

Gpars offers intuitive ways to handle tasks concurrently

import groovyx.gpars.*
GParsPool.withPool { def result = dataList.collectParallel { processItem(it) } }

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow