Posts

Showing posts with the label Scala functions

Scala Functions

Function : A function is computational unit in a program. Function : To define a function specify - name, parameter, body and return type.   Functions are implicitly declared as abstract if leave off the equal sign and method body. Remove = sign if not to return any thing. A function can have named and optional parameters. Use Unit if the function does not return anything. ( Unit is equivalent to Void in java) Function definition :   def functionName ([list of parameters]) : [ return type ]             Abstract Function :   Ex - def calculation (a:Int, b:String)         Non Abstract Function :    def functionName ([list of parameters]) : [ return type ] = { }              Example -       def calculation ( a : Int, b : Int): Int = {     var sum : Int = 0     sum = a ...