'How can I shorten this common pattern?
In our codebase we often encounter this pattern:
(_.isNil(x)) ? something(x) : null;
If something was a method on the object then the short version of it would be:
x?.something()
Is there a commonly accepted shortcut to the above? Perhaps something provided by lodash itself or some other library? Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
