Created
January 29, 2018 09:42
-
-
Save phaller/a4fade7906bad95a61f24311ace62d66 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
// Cells that depend on their handler context. | |
object HandlerCtx { | |
def apply(): HandlerCtx = { | |
new HandlerCtx | |
} | |
} | |
class HandlerCtx private { | |
self => | |
type Group | |
def register(cell: Cell { type Group = self.Group }): Unit = println("OK") | |
} | |
object Cell { | |
def apply()(implicit ctx: HandlerCtx): Cell { type Group = ctx.Group } = { | |
new CellImpl { type Group = ctx.Group } | |
} | |
} | |
trait Cell { | |
type Group | |
} | |
private class CellImpl extends Cell { | |
} | |
object Test { | |
def main(args: Array[String]): Unit = { | |
implicit val ctx = HandlerCtx() | |
val cell = Cell() | |
ctx.register(cell) | |
val ctx2 = HandlerCtx() | |
ctx2.register(cell) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment