Scala sum example code


Scala is a multi paradigm programming language, which is designed to integrate various features of object-oriented programming and functional programming.

Scala runs on a Java virtual machine and is compatible with existing Java programs.

Scala source code is compiled into Java bytecode, so it can run on top of the JVM and call existing Java class libraries.

def sum(f: Int => Int)(a: Int)(b: Int): Int = {

  def loop(n: Int, acc: Int): Int = {
   if (n > b) {
   } else {
    loop(n + 1, acc + f(n))
  loop(a, 0)
 sum(x => x)(1)(5)
 sum(x => x*x)(1)(5)
 //Use wildcards
 val sumSqure = sum(x => x * x)_ 

=>It can be understood as a mapping relationship
Corrilization and partial application function

Recommended Today

Query SAP multiple database table sizes

Query SAP multiple database table sizes Item code db02 Here are two approaches, In the first graphical interface, the results of the query data table are displayed in MB, and only one table can be queried at a time. SPACE—Segments—Detailed Analysis—Detailed Analysis  In the pop-up window segment / object, enter the name of the […]