groovy sort with comparator syntax

前端 未结 2 637
囚心锁ツ
囚心锁ツ 2020-12-16 10:59

I am just getting my feet wet with gremlin. I understand that gremlin is based on groovy. I found the documentation here, but I am still not sure what the syntax means.

2条回答
  •  心在旅途
    2020-12-16 11:14

    The spaceship operator <=> is an overloaded operator and represents compareTo(). Basically a<=>b is the same as a.compareTo(b)

    The example that you gave is using the sort() function with a closure (like lambda in Java8). The syntax for it is the following:

    .method{closureParameters -> statements}

    So your example is using the sort() function with a closure, inside that closure you use the spaceship (comparator) operator

    More about operator overloading here

提交回复
热议问题