Skip to content

Instantly share code, notes, and snippets.

@aholland
Last active June 15, 2017 15:33
Show Gist options
  • Save aholland/c9c2112b5aa40dcfc55fc91dc7f0b240 to your computer and use it in GitHub Desktop.
Save aholland/c9c2112b5aa40dcfc55fc91dc7f0b240 to your computer and use it in GitHub Desktop.
Long-winded because not able to refer to type in super-class type parameter list.
class Editor[T](initialValue: T)
class A[F, E <: Editor[F]](fieldMaker: () => F, edMaker: F => E) {
val field: F = fieldMaker()
val editor: E = edMaker(field)
}
locally { //Long
class B(opStringTypeMaker: () => (Option[String]))
extends A[Option[String], Editor[Option[String]]](opStringTypeMaker, opS => new Editor(opS)) {
}
val b = new B(() => Some("First"))
}
locally { //Better
type X = Option[String]
class B(opStringTypeMaker: () => X)
extends A[X, Editor[X]](opStringTypeMaker, new Editor(_: X)) {
}
val b = new B(() => Some("First"))
}
locally { //Ideal
class B(opStringTypeMaker: () => super.F)
extends A[Option[String], Editor[super.F]](opStringTypeMaker, new Editor(_: super.F)) {
}
val b = new B(() => Some("First"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment