In scala, As per §4.6 from reference if you declare below function
:
def f(n:Somthing) = {}
Then the return type of f
unless manually specified is taken (thanks to type inference) from the return type the block returns.
As per §4.6.3, the below is a procedure
def f(n:Somthing) {}
Where the return type of f
is Unit
even though it appears as Int
. Infact if you manually use return
rather than from implicit return
, in repl it gives:
scala> def plusThirty(a: Int, b: Int) {
| return a + b
| }
<console>:8: warning: enclosing method plusThirty has result type Unit: return value discarded
return a + b
^
plusThirty: (a: Int, b: Int)Unit
scala> plusThirty(22, step02(10))
So as said in comments, it should be below else it would had been a procedure:
def plusThirty(a: Int, b: Int) = {
a + b
}