Last active
June 15, 2017 15:33
-
-
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.
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
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