Created
July 15, 2017 18:41
-
-
Save kubukoz/c11732d3c887be506358f7de94f29551 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
object OneWayImplicits { | |
//outside implicits visible, but T is not visible inside | |
case class Outwards[T](value: T) extends AnyVal | |
//outside implicits invisible, T is visible inside | |
case class Inwards[T](value: T) extends AnyVal | |
implicit def outwardsFromT[T](implicit t: T): Outwards[T] = Outwards(t) | |
implicit def tFromInwards[T](implicit inw: Inwards[T]): T = inw.value | |
sealed trait X | |
def usesOutwards()(implicit ow: Outwards[X]) = { | |
//X is not implicitly visible here | |
val x: X = ow.value | |
} | |
//doesn't get X from implicit scope | |
def usesInwards(implicit iw: Inwards[X]) = { | |
//but X is implicitly visible here | |
??? | |
} | |
def composability(implicit x: Inwards[X]) = { | |
usesOutwards() //gets `Outwards(x.value)` | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment