Groovy web console

subscribe to the feed Subscribe
to this
site
GREP E A CI?CIA POR DETR? DO SWITCH DO GROOVY (via #groovywebconsole)
tweet this snippet Tweet
this
script

GREP E A CI?CIA POR DETR? DO SWITCH DO GROOVY

Published 2 years ago by Hubert Klein Ikkink / Jonatas Emidio with tags groovy grep switch
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
/**
GREP E A CI?CIA POR DETR? DO SWITCH DO GROOVY
Original post: http://mrhaki.blogspot.com.br/2009/08/groovy-goodness-grep-method.html
Vers? em portugu?: http://santograils.org/2015/06/03/grep-e-a-ciencia-por-detras-do-switch-do-groovy/

Link no c?igo fonte: https://github.com/groovy/groovy-core/blob/master/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L2412
*/

assert [true] == ['test', 12, 20, true].grep(Boolean), 'Class isInstance'
assert ['Groovy'] == ['test', 'Groovy', 'Java'].grep(~/^G.*/), 'Pattern match'
assert ['b', 'c'] == ['a', 'b', 'c', 'd'].grep(['b', 'c']), 'List contains'
assert [15, 16, 12] == [1, 15, 16, 30, 12].grep(12..18), 'Range contains'
assert [42.031] == [12.300, 109.20, 42.031, 42.032].grep(42.031), 'Object equals'
assert [100, 200] == [10, 20, 30, 50, 100, 200].grep({ it > 50 }), 'Closure boolean'