Skip to content

Instantly share code, notes, and snippets.

@viktorklang
Created July 6, 2009 12:32
Show Gist options
  • Save viktorklang/141406 to your computer and use it in GitHub Desktop.
Save viktorklang/141406 to your computer and use it in GitHub Desktop.
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