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
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With