This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RegexInterpolations._ | |
val str = "My hovercraft is full of eels" | |
str match { | |
case r"""My (\w+)$vehicle is full of (\w+)$stuff""" => | |
println(s"It is $stuff that my $vehicle is full of.") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.language.implicitConversions | |
final class Opt[+A] private(private val value: Any) extends AnyVal { | |
def isEmpty = value == null | |
def isDefined: Boolean = !isEmpty | |
def get: A = value.asInstanceOf[A] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Base { | |
def work() { | |
// do some work | |
} | |
} | |
trait Logging extends Base { | |
override def work() { | |
log("Doing work") | |
super.work() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// full implementation at https://github.com/ghik/selftyped | |
trait Base extends SelfTyped { | |
def same[T: Self]: T | |
def twice[T: Self]: T | |
} | |
trait SimpleSame extends Base { | |
// we can always safely return 'this' where self-type is expected |
NewerOlder