July 15, 2008

?~

Scala loves it some overloaded operators.

When working with the highly useful Can class from net.liftweb.util, the ?~ operator is equivalent to asking "is this Can empty?", but has the added bonus of returning a Failure object if it is.

This makes for pleasantly terse expressions that handle failure cases inline.

2 comments:

Andrey Andreev said...

Only nitpicking -- I don't think Scala has operators as such. ?~ is just a method on Can. A good choice of a language and framework! I am loving Scala as I am getting used to it. :)

Anonymous said...

Sure, technically ?~ is just a method on Can, but to the programmer it parses visually as an operator.