私がこの構造を持っていると想像してください:
class Foo {
String bar
}
Foo
ここで、bar
値がbaz_1
、baz_2
、およびのインスタンスがいくつかあるとしzab_3
ます。
bar
text を含む値のみを収集する collect ステートメントを書きたいと思いますbaz
。動作させることはできませんが、次のようになります。
def barsOfAllFoos = Foo.getAll().bar
assert barsOfAllFoos == [ 'baz_1', 'baz_2', 'zab_3' ]
def barsWithBaz = barsOfAllFoos.collect{ if( it.contains( "baz" ) { it } ) } // What is the correct syntax for this?
assert barsWithBaz == [ 'baz_1', 'baz_2' ]