andrea
andrea

Reputation: 521

What does -> mean in gradle scripts

What does the -> operator mean in gradle scripts. Is it a groovy thing? E.g.

def configureWarnings = { compiler ->
      compiler.args '-Wno-long-long', '-Wall', '-Wswitch-enum', '-pedantic', '-Werror'
}

OR

all { binary ->
    binary.component.sources.cpp.libs.each { lib ->
      if (lib instanceof Map && lib.containsKey('library') {
        //blah
      }
      if (lib instanceof Map && lib.containsKey('library')) {
        //blah
      }
    }
  }

Upvotes: 0

Views: 72

Answers (2)

Y. Mota
Y. Mota

Reputation: 1

In groovy, this syntax:

serves to separate the arguments from the closure body.

Closures Refference

They are comma-delimited, in case you have more than one parameter.

A simple example would be:

def list = ['a', 'b', 'c']

list.each { listItem ->
    println listItem
}

Which will result in:

a
b
c

In this context, you may even omit the parameter, and use the native call it. The code would be something like:

def list = ['a', 'b', 'c']

list.each {
    println it
}

Result would, and should, be the same.

If you have a map, for example, you could separate it's keys and values like this:

def map = ['Key_A':'a', 'Key_B':'b', 'Key_C':'c']
map.each { key, value ->
    println "$key has the value $value"
}

Naturally, the result would be:

Key_A has the value a
Key_B has the value b
Key_C has the value c

Hope that I've helped.

Upvotes: 0

RaGe
RaGe

Reputation: 23707

It is groovy syntax for parameters in a closure. See here for more information

Upvotes: 1

Related Questions