Ran Magen
01/26/2020, 5:26 AMexpand
function, we passed in a map where a key contained a function value:
[ pick: { Map<String, Object> stackMap, Object fallback -> stackMap.getOrDefault(stack, fallback) } ]
The template file we copied had stuff like:
replicas: ${pick(1, 'staging': 2, 'prod': 9)}
Now that I've converted the groovy code (in the build file, not the template) to Kotlin script and it now looks like
val pick = { stackMap: Map<String, Any>, fallback: Any -> stackMap.getOrDefault(stack, fallback) }
and I pass in to `expand`:
expand(mapOf("pick" to pick))
expansion fails saying this:
groovy.lang.MissingMethodException: No signature of method: Build_gradle$pick$1.call() is applicable for argument types: (LinkedHashMap, Integer) values: [[staging:2, prod:9], 1]
If possible, what's the right way to pass a function in expand
properties?Ran Magen
01/27/2020, 6:43 PM"pick" to object : groovy.lang.Closure<Any>(null) {
override fun call(vararg args: Any?): Any? {
val stackMap: Map<String, Any?> = args[0] as? Map<String, Any?> ?: emptyMap()
val fallback = args[1]
return stackMap.getOrDefault(stack, fallback)
}
}