Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • 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:

...

  1. 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()
  2. 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.

  3. 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.

...