Michał Jurczuk Michał Jurczuk - 6 months ago 53
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)