Can you make an anonymous val?
I'm thinking to do something like this:
case class NumIterations[A](num: Int)
case class Seed[A](seed: A)
case class Manipulate[A](f: A => A)
. . .
def funcWithGobsOfImplicitArgs[A](
implicit numIterations: NumIterations[A],
seed: Seed[A],
manipulate: Manipulate[A],
. . .
): A = . . .
def apply(): String = {
implicit val NumIterations[String](10) // This is where I want anonymous vals
implicit val Seed("xyz")
. . .
funcWithGobsOfImplicitArgs
}
Okay, making all of the function's arguments implicit is probably going overboard, but I do have a real application where it's handy to stick some function parameters in scope and then re-use and override them. This makes experimenting with the function very convenient. I can play with one parameter at a time explicitly and let all the others be supplied implicitly.
In this situation, it would be nice not to name the val, since the name takes up space in your head, and the full meaning of the val is provided by its type alone. When I only had one of these vals, I named it _
, thinking that Scala would treat it as a val that never gets referred to explicitly. But when I named two vals _
, Scala complained.