diff options
author | Adam Bard <github@adambard.com> | 2015-10-31 22:51:27 +0800 |
---|---|---|
committer | Adam Bard <github@adambard.com> | 2015-10-31 22:51:27 +0800 |
commit | 5b0db44e7c5f0a69dfa670eee13fbc011f76830a (patch) | |
tree | beab64f6c58ce9dcfed6bc3eef225df8f7ebe454 /scala.html.markdown | |
parent | e56bc6cbca1058f61f2fb7247888eb52068cb63d (diff) | |
parent | bc087b50370a3c32c35ef026047c2fa9db9944d8 (diff) |
Merge pull request #1953 from pikazlou/scala-functions
usage of named parameters in functions
Diffstat (limited to 'scala.html.markdown')
-rw-r--r-- | scala.html.markdown | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/scala.html.markdown b/scala.html.markdown index 192e03d7..bc8cd422 100644 --- a/scala.html.markdown +++ b/scala.html.markdown @@ -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: |