-
-
Save viktorklang/141406 to your computer and use it in GitHub Desktop.
This file contains 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
abstract class some[X](val value : X) { type T = X } | |
abstract class someFactory[S <: some[_]](val P : (S#T) => boolean) | |
{ | |
def apply(t : S#T) : Option[S] = if(P(t)) Some(fetch(t)) else None | |
def unapply(s : S) : Option[S#T] = if(s == null) None else Some(s.value) | |
def fetch(t : S#T) = mk(t) | |
protected[this] val mk : (S#T) => S | |
} | |
class Name private (v : String) extends some(v) | |
object Name extends someFactory[Name](_.length > 0){ val mk = new Name(_)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment