I have a method that calls a few other methods that make use of an implicit of type Foo. I’d like to make f implicit inside Foo. This is how I do it:
def myMethod(a: Int, f: Foo) = {
implicit val implicitF = f;
somethingThatNeedsFoo(a)
}
I don’t want to mark f implicit in the signature of myMethod since Foos are not implicit in the context that myMethod is being used. My question: is there a more idiomatic (or concise) way to achieve this effect than using a temporary variable?
You can pass implicit parameters explicitly, so even though there’s no Foo in the implicit scope of the caller, the caller can just pass it explicitly.
As commented, you can use this same trick to pass the Foo to
somethingThatNeedsFoo: