Optional Chaining

ThingsDB double dot notation is called optional chaining and allows using a property or function call.

Using the double dot (..) notation simple stops evaluation if the value before the double dot is either nil or an error.

For example:

arr = [{
    key: 'a',
    value: 123,
}, {
    key: 'b',
    value: 456,
}];
arr.find(|o| o.key == 'a')..value;

The above simple returns the value you expect:

123

But, what if we tried a key which does not exist?

arr = [{
    key: 'a',
    value: 123,
}, {
    key: 'b',
    value: 456,
}];
arr.find(|o| o.key == 'c')..value;

Using just .value would raise an error but now nil is returned:

null

This also works on an error.

// this property is only set if thing 12345 exists
try(thing(12345))..set('some_prop', 'some value');

The code above will not fail on ..set(..) as it will not be called on an error.