...
- More Enumerable methods for lists, arrays and maps (like map, pluck, invoke, ...)
Make logical operators (||, &&...) return the value instead of the boolean equivalent
eg.Code Block def x = '' || 'test' assert x == 'test' def x = null || 15 assert x == 15
- Make map creation more versatile. Add constructors that allow creation of a map from 2 collections "HashMap(keys, values)" or a list of entries "HashMap(itemlist)".
- Make a list and create an auto mapping:
...
Enable operator overloading for logical AND, logical OR, logical NOT. For logical AND and logical OR, the deferred evaluation of the right operand can be maintained by passing a Closure to the method. The signatures might be something like this:
Code Block Boolean land(Closure) Boolean lor(Closure) Boolean lnot()Enable assignment operator overloading. This is needed to allow a semantic like
Code Block MyBooleanClass bool = true
Note that overriding the assignment operator makes it significantly easier to replace numeric types too since one can handle cases like
Code Block MyNumericClass num = 10
which is not possible today.
Today due to "Groovy Truth" processing, any non-null object reference (that is not a Boolean) will evaluate to true. To enable user-defined Boolean type data, Groovy Truth would need to be modified to optionally "unbox" a non-null object reference into a Boolean value if it has a booleanValue() method. This would allow one to do something like this
Code Block MyBooleanType bool = something(); if bool || somethingElse() { ... }In such a case, the bool instance can be either false or true and can be directly used for control flow and other operations that normally expect a Boolean.
With these changes, user-defined boolean replacement classes would get first-class support in the language.
...