Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overview of Scala method and function syntax

Tags:

scala

I am learning Scala and I wonder if an overview of method/function syntax exists? When to use parantheses, different ways of writing etc. Also the conventions would be nice.

like image 910
LuckyLuke Avatar asked Feb 27 '12 08:02

LuckyLuke


People also ask

What is the difference between a function and a method in Scala?

However, functions are an object which is initialized in a variable, but methods start with the 'def' keyword followed by the method name, parameter list, method body with the return value. The syntax for method declaration and definition in Scala is below: 'def': keyword which is used to declare methods.

How do you declare a function in Scala?

A Scala function declaration has the following form − def functionName ([list of parameters]) : [return type] Methods are implicitly declared abstract if you don’t use the equals sign and the method body.

Which functions do not return anything in Scala?

The functions which do not return anything in Scala, they are called procedures. object Hello { def printMe ( ) : Unit = { println ("Hello, Scala!") } } Scala provides a number of syntactic variations for invoking methods. Following is the standard way to call a method −

What is Scala programming language?

Scala is a functional programming language where it contains both functions as first-class values and methods and has both similarities and dissimilarities. Both the functions and methods are a block of the reusable code also used to store the repeated code in one place, which makes a function call to performs a particular specific task.


2 Answers

I think all the information you're requesting is in the Scala docs.

Specifically, the style guide and the cheatsheet.

like image 191
cha0site Avatar answered Oct 18 '22 21:10

cha0site


Effective Scala from Twitter is also an excellent resource. I've adopted it for all my Scala projects.

like image 45
Ryan Avatar answered Oct 18 '22 20:10

Ryan