Skip to content
Advertisement

what does the -> operator means and usages in grails?

I am new working with grails application.I am confusing about this -> operator in grails. Can anyone give me clear concept about this? or Give me any reference about this that can be easy for me. I am already reading online documentation and some books but i am still confusing about this operator and usages.

Advertisement

Answer

This is the parameter indicator in a Groovy closure. You can find out more about closures here.

-> is a symbol indicating the end of parameters list for a closure in Groovy.

In the first example (given in comments) you have a closure called printSum and it takes two parameters; a and b:

def printSum = { a, b -> 
  print a+b 
}

In the second example (given in the comments) you have a named criteria called oldPublicationsLargerThan and it takes one parameter called pageCount.

oldPublicationsLargerThan { pageCount -> 
  def now = new Date() 
  lt 'datePublished', now - 365 
  gt 'numberOfPages', pageCount 
} 
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement