Created
January 28, 2013 00:25
-
-
Save travisbrown/4651653 to your computer and use it in GitHub Desktop.
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
sealed trait Item | |
case class Marble() extends Item | |
case class Book() extends Item | |
sealed trait Container[Item] | |
case object Pouch extends Container[Marble] | |
case object Shelf extends Container[Book] | |
trait ContainerFor[I <: Item] { def apply(): Container[I] } | |
case class in[I <: Item](apply: Container[I]) extends ContainerFor[I] | |
def where[I <: Item](implicit mapping: ContainerFor[I]) = mapping() | |
implicit object putMarble extends in(Pouch) | |
implicit object putBook extends in(Shelf) | |
/* And then: | |
scala> where[Marble] | |
res0: Container[Marble] = Pouch | |
scala> where[Book] | |
res1: Container[Book] = Shelf | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment