mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 09:41:36 +00:00
Merge pull request #1953 from pikazlou/scala-functions
usage of named parameters in functions
This commit is contained in:
commit
5b0db44e7c
@ -169,6 +169,12 @@ def sumOfSquaresShort(x: Int, y: Int): Int = x * x + y * y
|
||||
// Syntax for calling functions is familiar:
|
||||
sumOfSquares(3, 4) // => 25
|
||||
|
||||
// You can use parameters names to specify them in different order
|
||||
def subtract(x: Int, y: Int): Int = x - y
|
||||
|
||||
subtract(10, 3) // => 7
|
||||
subtract(y=10, x=3) // => -7
|
||||
|
||||
// In most cases (with recursive functions the most notable exception), function
|
||||
// return type can be omitted, and the same type inference we saw with variables
|
||||
// will work with function return values:
|
||||
|
Loading…
Reference in New Issue
Block a user