Skip to content

Instantly share code, notes, and snippets.

@guizmaii
Created February 7, 2022 05:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guizmaii/b01b28f5cefb4d7294bdcd81c9b289a8 to your computer and use it in GitHub Desktop.
Save guizmaii/b01b28f5cefb4d7294bdcd81c9b289a8 to your computer and use it in GitHub Desktop.
trait Instance[T] {
def t: T
}
object Instance {
def apply[T](v: T): Instance[T] = new Instance[T] { override def t: T = v }
}
sealed trait Typed {
type T
}
sealed trait TypedValue extends Typed {
def value: T
}
object Typed {
def instance(typed: Typed): Instance[typed.T] =
typed match {
case t: TypedValue => Instance(t.value) // To make this compile: Instance(t.value.asInstanceOf[typed.T])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment