softshipper
softshipper

Reputation: 34071

Where should I define implicit arguments in the apply method?

I would like to define two implicit parameters in the apply method as the following:

object WsGraph {

  def apply(logger: Logger, sink: Sink[Message, Future[Done]])
           (implicit system: ActorSystem, implicit executor: ExecutionContextExecutor) {

  }
}

But the compiler does not allow this. How to do it correctly?

Upvotes: 3

Views: 58

Answers (2)

Vivek
Vivek

Reputation: 405

Multiple implicit parameters do not work. It should be like:

object WsGraph {

  def apply(logger: Logger, sink: Sink[Message, Future[Done]])
           (implicit system: ActorSystem, executor: ExecutionContextExecutor) {

  }
}

Upvotes: 2

Krzysztof Atłasik
Krzysztof Atłasik

Reputation: 22595

You just need to add one keyword implicit at the beginning of the second argument list and all arguments on it will be implicit:

object WsGraph {      
    def apply(logger: Logger, sink: Sink[Message, Future[Done]])
               (implicit system: ActorSystem, executor: ExecutionContextExecutor) {

    }
}

Upvotes: 5

Related Questions