I saw in some of the code which I am unable to understand the purpose of << like in the following sample code
def renderFiles(args) {
def model = []
This is a leftShift
operator. In groovy operator overloading is implemented, see here and the new docs for reference . In this particular case adding an element to list operation is overloaded.
Instead of:
model.add(createModel(fileArgs.id,fileArgs.path,fileArgs.ext))
You can simply write:
model << createModel(fileArgs.id,fileArgs.path,fileArgs.ext)
It's a kind of a shorthand. There are also other operators overridden for List class, e.g. plus()
, minus()
. See here.
In groovy <<
operator adds result of expression on the right side to the collection on the left side