Groovy web console

subscribe to the feed Subscribe
to this
site
Upcoming refinements of Groovy 1.8's upcoming "extended command expression" DSL support (via #groovywebconsole)
tweet this snippet Tweet
this
script

Upcoming refinements of Groovy 1.8's upcoming "extended command expression" DSL support

Published 4 years ago by glaforge with tags dsl gep3
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
/* Groovy 1.8-beta-4 will feature further enhancements to the new extended command expression support */

// case             a b  c d
// equivalent       a(b).c(d)

def turned = false
def (left, right) = ['left', 'right']
def turn = { String s -> [then: { turned = true }] }

turn left then right

assert turned

// case            a b  c
// equivalent      a(b).getC()

def drank = false
def more = 'more'
def drink = { String s -> [milk: { drank = true }()] }

def d = drink more milk

assert drank

// case          a {}  b {}  c {}
// equivalent    a({}).b({}).c({})

def bdd = 0
def given = { c1 -> c1(); [when: { c2 -> c2(); [then: { c3 -> c3() }] }]}

given {
    bdd++
} when {
    bdd++
} then {
    bdd++
}

assert bdd == 3

// case            a b  c()
// equivalent      a(b).c()

def built = false
def all = 'all'
def select = { String s -> [build: { built = true }] }

select all build()

assert built

// case            a b  c() d e
// equivalent      a(b).c().d(e)

def uploaded = false
def (file, here) = ['file', 'here']
def upload = { String s1 -> [check: {-> [decompress: { String s2 -> uploaded = true }] }]}

upload file check() decompress here

assert uploaded

// case            a b  c[1](){} d e
// equivalent      a(b).c[1](){}.d(e)

def resolved = false
def (cube, topLayer, down) = ['cube', 3, 'down']
def resolve = { String s1 -> [move: [0, 1, 2, { c -> [upside: { String s2 -> resolved = true }] }]] }

resolve cube move[topLayer](){} upside down

assert resolved