Refactored example to Option.collect method.

rebase of #3862

already LGTMed