Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any usage of implicit functions with several parameters in Scala?

Tags:

scala

Implicit functions with several parameters are allowed, that is:

implicit def it(path: String, category: String):Iterator[String] = ...

But can the Scala compiler do something useful with it? If not, why doesn't it complain?

like image 840
yura Avatar asked Aug 29 '11 20:08

yura


People also ask

What is the use of implicit in Scala?

Implicit parameters are the parameters that are passed to a function with implicit keyword in Scala, which means the values will be taken from the context in which they are called.

How many implicit parameters can an instance method have?

An implicit parameter list (implicit $p_1$,$\ldots$,$p_n$) of a method marks the parameters $p_1 , \ldots , p_n$ as implicit. A method or constructor can have only one implicit parameter list, and it must be the last parameter list given.

How do you pass an implicit parameter?

The implicit parameter in Java is the object that the method belongs to. It's passed by specifying the reference or variable of the object before the name of the method. An implicit parameter is opposite to an explicit parameter, which is passed when specifying the parameter in the parenthesis of a method call.

What are implicit classes in Scala?

Scala 2.10 introduced a new feature called implicit classes. An implicit class is a class marked with the implicit keyword. This keyword makes the class's primary constructor available for implicit conversions when the class is in scope. Implicit classes were proposed in SIP-13.


1 Answers

Yes, the compiler can do something with it if you ask for such an implicit.

def f(implicit ev: (String, String) => Iterator[String]) = ...
like image 177
Daniel C. Sobral Avatar answered Sep 25 '22 15:09

Daniel C. Sobral