Let's say this is the original with pattern-matching:
val s: String = option match {
case None => getValue
case Some(foo) => foo.asText
}
You could write this as:
val s: String = option.map(_.asText).orElse(getValue)
I might have misunderstood, it's just hit midnight and I've had a long
day. If I have, can you give a code example? Tony Morris' cheat
sheet might help; http://blog.tmorris.net/scalaoption-cheat-sheet/
On Tue, Oct 30, 2012 at 11:38 PM, Josh Berry <[email protected]> wrote:
> On Tue, Oct 30, 2012 at 10:28 PM, Ricky Clarkson
> <[email protected]> wrote:
>> 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.
>
> I'm converting to a string. Either calling .asText or .getValue,
> essentially. And if it was a class I didn't know, just an empty
> string. Each case is currently just a printf saying what happened
> followed by the method I'm calling, which depends on the type of the
> value held. (I may have removed the printfs, can't remember.)
>
> The java call is HtmlUnit's querySelector method.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Java Posse" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> 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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/javaposse?hl=en.