-
-
Save timperrett/141408 to your computer and use it in GitHub Desktop.
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
abstract class Foo[X](val value : X) { type T = X } | |
abstract class FooFactory[S <: Foo[_]](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 Foo(v) | |
object Name extends FooFactory[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