- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Better Option Use?
Sat, 2011-12-17, 02:04
Hello,
Is there a more concise way of doing this with an Option:
if( something.isDefined ) goDoIt( something.get )
(Yes, goDoIt() could accept an Option but that just moves the if
statement into goDoIt.)
Thanks for any ideas.
-gz
Sat, 2011-12-17, 02:31
#2
Re: Better Option Use?
On Sat, Dec 17, 2011 at 11:04 AM, Greg Zoller <gzoller@gmail.com> wrote:
something.foreach(goDoIt)
See: http://blog.tmorris.net/scalaoption-cheat-sheet/
-jason
Is there a more concise way of doing this with an Option:
if( something.isDefined ) goDoIt( something.get )
(Yes, goDoIt() could accept an Option but that just moves the if
statement into goDoIt.)
something.foreach(goDoIt)
See: http://blog.tmorris.net/scalaoption-cheat-sheet/
-jason
Sat, 2011-12-17, 04:51
#3
Re: Better Option Use?
Thats a fantastic cheat sheet, thanks!
On Dec 16, 7:12 pm, Jason Zaugg wrote:
> On Sat, Dec 17, 2011 at 11:04 AM, Greg Zoller wrote:
> > Is there a more concise way of doing this with an Option:
>
> > if( something.isDefined ) goDoIt( something.get )
>
> > (Yes, goDoIt() could accept an Option but that just moves the if
> > statement into goDoIt.)
>
> something.foreach(goDoIt)
>
> See:http://blog.tmorris.net/scalaoption-cheat-sheet/
>
> -jason
something.foreach(goDoIt)
On Friday, December 16, 2011, Greg Zoller wrote: