Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forbid using named arguments in Scala

Tags:

scala

Is there a way in Scala to forbid using named arguments for a function?

Example:

def func(num: Int, power: Int) = math.pow(num, power)

func(3, 2)                   // OK
func(num = 3, power = 2)     // Forbidden
like image 329
Graduate Avatar asked Dec 21 '25 05:12

Graduate


1 Answers

You could use a function literal:

val func = (num: Int, power: Int) => math.pow(num, power)

func(3, 2)
func(num = 3, power = 2)  // "error: not found: value num"

(Although Function2's apply still has argument names:)

func(v1 = 3, v2 = 2)
like image 150
0__ Avatar answered Dec 23 '25 20:12

0__