Michał Jurczuk Michał Jurczuk - 3 months ago 17
Scala Question

Simplify Option creation in Scala to avoid conditions

Now I create

Option
using
if
condition:

if (lastTime > 0)
Some(lastTime)
else
None


is it possible to simplify such expression?

Answer

Option(lastTime).filter(_ > 0)