Scala - Higher Order Functions Code Example

The code for Higher Order Functions

object MyClass {
    def main(args: Array[String]) {
        // list of inetgers
        val list = List(1, 3, 5)
        
        // Method for some operation
        def square_values = (num: Int) => num * num
        
        // Higher order function 
        val result = list.map(num => square_values(num))
        
        // Printing the result
        println("Square of numbers of the list is: " + result)
    }
}

/*
Output:
Square of numbers of the list is: List(1, 9, 25)
*/
Code by IncludeHelp, on August 15, 2022 22:45

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.