'empty' is a handy Workday Studio keyword

Posted 2 months, 2 weeks ago

TIL about the MVEL empty keyword. For the longest time, I've been using props['blah'] != '' or len(props['blah'] == 0 comparisons in Studio integrations. I should have been using empty the whole time!

Here's some test results from an integration message:

Is nil empty? true
Is null empty? true
Is '' empty? true
Is "" empty? true

Is null nil? true
Is "" null? false
Is "" nil? false

The old way:
    Is len("")=0? true

This was the "code" used to generate the message:

Is nil empty? @{nil == empty}
Is null empty? @{null==empty}
Is '' empty? @{''==empty}
Is "" empty? @{""==empty}

Is null nil? @{null==nil}
Is "" null? @{""==null}
Is "" nil? @{""==nil}

The old way:
    Is len("")=0? @{"".length()==0}

From the docs:

The MVEL docs says empty is "a special literal for testing for emptiness of a value, cleverly named empty."

The example expression will be ‘’true’’ if the value of foo satisfies any of the requirements of emptiness.

Unfortunately, the docs don't elaborate on the definition of "emptiness", so I guess that's left up to the user to test 🤷.