Groovy web console

subscribe to the feed Subscribe
to this
site
First class functions (via #groovywebconsole)
tweet this snippet Tweet
this
script

First class functions

Published 1 month ago by Frerich
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def f(x) { return x + 1 }
def g(x) { return x * 2 }

// Trying to approximate 'e = true ? f : g'
e = { x -> true ? f(x) : g(x) }

println e(13)