I'm finding that I often have to chain together functions that work on an Option
and return a different Option
that look something like this:
if(foo.isDefined) someFunctionReturningOption(foo.get) else None
Is there a cleaner way to do this? This pattern gets quite verbose with more complicated variables.
I'm seeing it a fair bit in form handling code that has to deal with optional data. It'll insert None
if the value is None
or some transformation (which could potentially fail) if there is some value.
This is very much like the ?.
operator proposed for C#.