score:1
Indeed it's the correct behaviour. implicit
values are only searched in current scope and calling print
outside IntPrinter
means it's not on the class scope (obviously) and the reason why I had to import
it.
The correct way to do what I wanted:
case class IntPrinter(implicit val i: Int) {
def print()(implicit i: Int) = println(i)
def printProxy() = print()
}
And then calling p.printProxy
behaves like I wanted it to behave (because printProxy
is inside IntPrinter
's scope.)
score:1
I'm not sure I understand. Why is it that you need implicits here at all? It seems that you could just as easily do this:
scala> case class IntPrinter(i: Int) { def print() = println(i) }
defined class IntPrinter
scala> val p = IntPrinter(9)
p: IntPrinter = IntPrinter(9)
scala> p.print()
9
or, if you really have use for IntPrinter
taking an implicit:
scala> case class IntPrinter(implicit val i: Int) { def print() = println(i) }
defined class IntPrinter
scala> val p = IntPrinter()(9)
p: IntPrinter = IntPrinter(9)
scala> p.print()
9
Basically, in that case, you need not specify that it is implicit twice; when you declared it implicit the first time, that made i
a member of the class, so you can continue to reference it throughout the rest of the class—just like you could with any other data member of a class.
Source: stackoverflow.com
Related Query
- Using explicit value passed to implicit parameter as new implicit value
- Error: "could not find implicit value for parameter readFileReader" trying to save a file using GridFS with reactivemongo
- Could not find implicit value for parameter write eror, yet I defined the handler using the macro
- Using scalamock: Could not find implicit value for evidence parameter of type error
- Is there any style guidelines about using implicit parameter with default value in scala?
- How to fix an issue "could not find implicit value for evidence parameter of type" when using magnolia
- serializing polymorphic classes using spray.json getting could not find implicit value for evidence parameter of type
- Play 2.4: Form: could not find implicit value for parameter messages: play.api.i18n.Messages
- could not find implicit value for evidence parameter of type org.apache.flink.api.common.typeinfo.TypeInformation[...]
- How can I fix the missing implicit value for parameter ta: TildeArrow in a test spec
- Could not find implicit value for evidence parameter of type scala.reflect.ClassManifest[T]
- Could not find implicit value for parameter flash
- scalaz List[StateT].sequence - could not find implicit value for parameter n: scalaz.Applicative
- spray-json error: could not find implicit value for parameter um
- Scala, Play Framework Slick issue - could not find implicit value for parameter rconv
- could not find implicit value for parameter e
- could not find implicit value for parameter system: akka.actor.ActorSystem
- saveTocassandra could not find implicit value for parameter rwf
- Dealing with explicit parameters required by inner implicit parameter lists
- Why can't Scala find implicit value for parameter scala.slick.session.Session?
- Play 2.5 Migration Error: Custom Action with BodyParser: could not find implicit value for parameter mat: akka.stream.Materializer
- could not find implicit value for evidence parameter of type scalaz.Applicative
- implicit parameter VS default parameter value
- Play 2.5 with Akka - could not find implicit value for parameter timeout: akka.util.Timeout
- Running scalaz-stream's Process gives could not find implicit value for parameter C: scalaz.Catchable[F2]?
- Could not find implicit value for parameter lgen: shapeless.LabelledGeneric.Aux
- How to get the runtime value of parameter passed to a Scala macro?
- Slick error while compiling table definitions: could not find implicit value for parameter tm
- value flatMap is not a member of type parameter F[Long] when using cats.effect
- Could not find implicit value while using Context Bound
More Query from same tag
- AJAX file upload in Play Framework 2.1 RC1 delivers an empty file
- Correct method signature for RichGroupReduceFunction?
- Scala: how to force type to be provided
- Scala, ZIO - how to convert ZIO to Task and get result?
- run the savina code https://github.com/shamsimam/savina
- Why does the Scala compiler prefer to infer an argument of value null as Array[Char] instead of Object?
- How do I filter Nones out of a column of options?
- Clearing output from Scala Worksheet
- Running scalatest classes from sbt file
- Duplicated Spark Context with IntelliJ in Worksheet
- Scala: aggregate column based file
- Declaration of exchanges and queues in Akka AMQP
- Factory method with dependent type
- How to match on unknown generic type without warnings
- Bidirectional binding fails to bind
- Scala reduceLeft: 0.asInstanceOf[B]
- Stack-safe unfold
- Solution for DuplicateKey: E11000 duplicate key error index with Play! 2.0 Framework
- How to consume from a different Kafka topic in each batch of a Spark Streaming job?
- How to stack ReaderT and WriterT transformers in scalaz?
- Fetch outgoing edge property value between two vertices in scala gremlin
- Play WS request times out sooner than withRequestTimeout
- Build.scala:1: not found: object sbt
- What is the practical usage of Private Constructor in Scala
- Sending post with json using spray?
- scala error : ';' expected but 'import' found
- What does spark exitCode: 12 mean?
- How to make RegEx more performant?
- type-parametrized object in Scala
- Chisel switch statement doesn't appear to work in manner outlined in official tutorial