Ruby-style trailing conditionals in Scala
by Peter.
Ruby code often has code with trailing conditionals, which can look pretty neat.
person = Person.get(name) unless name.nil? |
(Note: I really don’t know Ruby, I just saw syntax like this and thought was cool.)
So, of course I had to implement it in Scala:
You get optional values:
Pretty cool, no?
I tried and failed to come up with some sort of fancy extractor object that would let me use unless
in pattern matching:
1001 match { case n unless n % 2 == 0 => println(n) } |
Can you figure out a way?