Given the following object with 2 implicits:
scala> object Foo {
| implicit def stringToInt(x: String) = 555
| implicit def stringToBoolean(x: String) = true
| }
warning: there were two feature warnings; re-run with -feature for details
defined object Foo
I can use them:
scala> def f(x: Int) = x
f: (x: Int)Int
scala> import Foo._
import Foo._
scala> f("asdf")
res0: Int = 555
scala> def g(b: Boolean) = b
g: (b: Boolean)Boolean
scala> g("asdfasdf")
res1: Boolean = true
Then, I tried to disable the stringToInt
implicit.
scala> import Foo.{stringToInt => _}
import Foo.{stringToInt=>_}
But, evidently, that did not work.
scala> f("adsfasdf")
res2: Int = 555
After wildcard importing implicits, is it possible to hide them?
Basically, I'd like to use all of Foo
's implicits, minus a single one, stringToInt
.
Note - of course I could simply do import Foo.stringToBoolean
only, but, for my scenario, Foo
has ~25 imports, and I want to use 24 of them. As a result, it's more concise to use all, and then subtract one.
The REPL just approximates what to import from history, and one approximation is always to use imported implicits.
In normal code, you would disable an implicit by shadowing the identifier.
Best shot is:
or
The idea is to introduce the shadowing variable into the scope of the REPL template for the current line.
There is an existing syntax to disallow a specific import. It is an extension of the syntax for renaming/aliasing an import:
To hide an import, you can alias it to "_":
Similarly, to import all of an object, except for a specific entry, use: