Super minimalistic non-obtrusive utility to access nested models in a slimmer and arguably more legible manner, while maintaining debuggability.
Loosely inspired by the new Javascript language feature: "optional chaining"
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining
myArray := { 2. nil }.
myArray _ first _ squared _ * 12. "=> prints 48"
myArray _ second _ squared _ * 12. "=> prints nil"
myArray _ second _ squared * 12. "=> raises an error"
myArray _ second _ squared isNil. "=> prints true"
To install this library you clone this repository and load BaselineOfNilSafeSend. This can be done using the Iceberg UI tools and with the following script:
Metacello new
baseline: 'NilSafeSend';
repository: 'github://Ironirc/Nil-Safe-Send:main';
load.
Sending and underscore to a receiver, just returns the receiver, or in case of nil, returns a special intermediary object.
This intermediary object is the sole instance of MessageSwallower (subclass of UndefinedObject). It's doesNotUnderstand returns nil.
This makes the effect very local and controllable
Is it ok to claim underscore '_' as global method name?
- Look for better examples
- More and better tests