How to define a list of functions of the same arity in Scala? -



How to define a list of functions of the same arity in Scala? -

in various lisps, it's possible me create sequence of functions if they'd been normal values:

class="lang-lisp prettyprint-override">(def ops [+ - * /])

which can iterate through, again, if normal values:

(doseq [op ops] // (doseq (op ops) (op <- ops) in scala (println (op 1 2 3 4)))

now, i've tried few things in scala, of them failing:

scala> list(+, -, *, /) <console>:1: error: illegal start of simple look list(+, -, *, /) ^ scala> list[double => double](+, -, *, /) <console>:1: error: illegal start of simple look list[double => double](+, -, *, /) ^ scala> list[double => double](+_, -_, *_, /_) <console>:8: error: not found: value * list[double => double](+_, -_, *_, /_) ^ <console>:8: error: not found: value / list[double => double](+_, -_, *_, /_) ^

so what's right procedure of defining list of functions/operators in scala?

the problem these functions binary operators, i.e., take two operands , homecoming one. have use:

list[(double, double) => double](_ + _, _ - _, _ * _, _ / _)

scala higher-order-functions

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -