Skip to content

Instantly share code, notes, and snippets.

@phaller
Created January 29, 2018 09:42
Show Gist options
  • Save phaller/a4fade7906bad95a61f24311ace62d66 to your computer and use it in GitHub Desktop.
Save phaller/a4fade7906bad95a61f24311ace62d66 to your computer and use it in GitHub Desktop.
// 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