Why we need implicit parameters in scala?

akka, scala

Solution

In the code from Akka you linked, it is true that executor could be just passed explicitly. But if there was more than one `Future` used throughout this method, declaring implicit parameter would definitely make sense to avoid passing it around many times.

So I would say that in the code you linked, implicit parameter was used just to follow some code style. It would be ugly to make an exception from it.

Problem

I am new to scala, and today when I came across this akka source code I was puzzled: ``` def traverse[A, B](in: JIterable[A], fn: JFunc[A, Future[B]], executor: ExecutionContext): Future[JIterable[B]] = { implicit val d = executor scala.collection.JavaConversions.iterableAsScalaIterable(in).foldLeft( Future(new JLinkedList[B]())) { (fr, a) ⇒ val fb = fn(a) for (r ← fr; b ← fb) yield { r add b; r } } } ``` Why the code is written using implicit parameters intentionally? Why can't it be written as: ``` scala.collection.JavaConversions.iterableAsScalaIterable(in).foldLeft( Future(new JLinkedList[B](),executor)) ``` without decalaring a new implicit variable `d`? Is there any advantage of doing this? For now I only find implicits increase the ambiguity of the code.

Original source

Related problems