Skip to content

Instantly share code, notes, and snippets.

View aesteve's full-sized avatar
👋

Arnaud Esteve aesteve

👋
  • Sant Cugat del Vallès, Barcelona, Catalonia, Spain
  • X @arnaudesteve
View GitHub Profile
@timyates
timyates / uncurry.groovy
Created May 5, 2016 20:42
Uncurry(?) in Groovy
// Change a method reference into a closure that takes the delegate as the first parameter
import org.codehaus.groovy.runtime.MethodClosure
def uncurry(MethodClosure c) {
{a, ...b -> a."$c.method"(*b) }
}
// So uncurrying Number.plus gives us a closure that will take {x, y -> x.plus(y)}
def plus = uncurry(Number.&plus)
assert plus(1, 2) == 3
@sidharthkuruvila
sidharthkuruvila / gist:3154845
Created July 21, 2012 06:30
Utility to functions to convert between camel case and underscore separated names
/**
* Takes a camel cased identifier name and returns an underscore separated
* name
*
* Example:
* camelToUnderscores("thisIsA1Test") == "this_is_a_1_test"
*/
def camelToUnderscores(name: String) = "[A-Z\\d]".r.replaceAllIn(name, {m =>
"_" + m.group(0).toLowerCase()
})