3 ms·
The difference here is callers of mainWithOptions won't have to do the null/undefined check again. They get back an option so they can just keep calling map.
by bern4444 5y ago
The difference here is callers of mainWithOptions won't have to do the null/undefined check again.
They get back an option so they can just keep calling map.
And that's true all the way up the call stack.
But in the main example, since it may always return null/undefined, every caller up the stack will also have to do this check.
Null and undefined are used for lots of different purposes by lots of different people. None (and Options more generally) is much more specific - there may or may not be a value here but you can safely work with this value regardless without needing to first check.
The checking is built into the object for you.
Neither way is right, just about what you prefer. I find the ergonomics of options much nicer than null/undefined.