This advice is a variant of the "be as unspecific as possible regarding inputs and as specific as possible regarding outputs" rule of thumb.
Usually if you have a method that takes a plain non-null value, you can map it over the Optional
, so the plain version is strictly more unspecific regarding inputs. However there are a bunch of possible reasons why you would want to require an Optional
argument nonetheless:
- you want your function to be used in conjunction with another API that returns an
Optional
- Your function should return something other than an empty
Optional
if the given value is empty You thinkOptional
is so awesome that whoever uses your API should be required to learn about it ;-)