Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

: _* notation in scala [duplicate]

Tags:

scala

I am encountering this : _* notation in many spark-scala answers, but couldn't find any documentation. What does it mean actually? An example of such usage is in the answer to this question

How to use DataFrame filter with isin in Spark Java?

line:

df.filter(col("something").isin(list: _*)
like image 404
pasternak Avatar asked Sep 25 '17 05:09

pasternak


People also ask

What is infix operator notation in Scala?

For a long time, Scala has supported a useful “trick” called infix operator notation. If a method takes a single argument, you can call it without the period after the instance and without parentheses around the argument. This post describes changes in Scala 3.

What are regular expressions in Scala?

Regular Expressions explain a common pattern utilized to match a series of input data so, it is helpful in Pattern Matching in numerous programming languages. In Scala Regular Expressions are generally termed as Scala Regex.

What are reserved symbols in Scala?

Reserved symbols are special character, punctuation that have a special meaning in Scala. They cannot be used as an identifier (variable name or class name). For each reserved symbol there is a list of use cases and for each use case there is a concise explanation.

What are operators in Scala?

Scala - Operators - An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. Scala is rich in built-in operators and provides the


1 Answers

To understand it, lets take an example

scala> def echo(args: String*) =
for (arg <- args) println(arg)
echo: (args: String*)Unit

scala>  val arr = Array("What's", "up", "doc?")
arr: Array[String] = Array(What's, up, doc?)

scala> echo(arr)
<console>:14: error: type mismatch;
 found   : Array[String]
 required: String
       echo(arr)
scala> echo(arr: _ *)
What's
up
doc?

This notation,arr:_* tells the compiler to pass each element of arr as its own argument to echo , rather than all of it as a single argument.

like image 101
Mahesh Chand Avatar answered Sep 17 '22 16:09

Mahesh Chand