Skip to content

Instantly share code, notes, and snippets.

@Jasper-M
Created February 28, 2018 18:50
Show Gist options
  • Save Jasper-M/dc46ffc52bb968c7dbe10db61f3f130b to your computer and use it in GitHub Desktop.
Save Jasper-M/dc46ffc52bb968c7dbe10db61f3f130b to your computer and use it in GitHub Desktop.
Implicits that are only implicitly available
scala> object Module {
| type Foo[T] = Internal.Foo[T]
| object Foo {
| def pubMethod = "Hi!"
| }
|
| private[Module] object Internal {
| trait Foo[T]
| object Foo {
| implicit def FooString = new Foo[String] {
| override def toString = "it's me!"
| }
| }
| }
| }
defined object Module
scala> implicitly[Module.Foo[String]]
res0: Module.Foo[String] = it's me!
scala> Module.Foo.pubMethod
res1: String = Hi!
scala> Module.Internal.Foo.FooString
<console>:13: error: object Internal in object Module cannot be accessed in object Module
Module.Internal.Foo.FooString
^
scala> object Module {
| trait Foo[T]
| private[Module] object Foo {
| implicit def FooString = new Foo[String] {
| override def toString = "it's me!"
| }
| }
| }
defined object Module
scala> implicitly[Module.Foo[String]]
res0: Module.Foo[String] = it's me!
scala> Module.Foo.FooString
<console>:13: error: object Foo in object Module cannot be accessed in object Module
Module.Foo.FooString
^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment