You don't necessarily have to write methods that take Option, you can
write normal methods and lift them into Option with map.  That's
generally better than writing methods that take Option but just return
None if the Option is None.

Josh's example needs fleshing out, it's not even clear whether he uses
the result of the pattern-matching or does it just for the
side-effects.  That has a bearing on how I'd prefer to write it.

On Tue, Oct 30, 2012 at 11:14 PM, Cédric Beust ♔ <ced...@beust.com> wrote:
> On Tue, Oct 30, 2012 at 7:11 PM, Josh Berry <tae...@gmail.com> wrote:
>>
>> On Tue, Oct 30, 2012 at 10:03 PM, Ricky Clarkson
>> <ricky.clark...@gmail.com> wrote:
>> > As for pattern-matching, there's nothing inherently bad about it, but
>> > usually or perhaps always with scala.Option, there's a better way of
>> > writing code using HOFs.
>>
>> So, in my example, what should I have done instead?  I should say the
>> function returning an Object that might be null was from a java
>> library.  And the "do something with class I know" was less than 2
>> lines in each case.  Seemed perfectly succinct and readable.
>
>
> It depends on the functions that you are calling in the Some and None cases:
> if they belong to an external API, extracting the value is your only opt...
> er... choice. However, if you are calling methods that you wrote, consider
> rewriting them to accept an Option and just call flatMap with that method on
> your option.
>
> --
> Cédric
>
> --
> You received this message because you are subscribed to the Google Groups
> "Java Posse" group.
> To post to this group, send email to javaposse@googlegroups.com.
> To unsubscribe from this group, send email to
> javaposse+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/javaposse?hl=en.

-- 
You received this message because you are subscribed to the Google Groups "Java 
Posse" group.
To post to this group, send email to javaposse@googlegroups.com.
To unsubscribe from this group, send email to 
javaposse+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

Reply via email to