SCALA FUNCTION STYLE

来源:互联网 发布:lvs keepalived nginx 编辑:程序博客网 时间:2024/06/05 05:26

SCALA FUNCTION


normal function


  • style def func() = {}
  • e.g.
    a + b}

simplify note


  • style _
  • e.g.
```##anonymous function--------------- style `{(params) => blocks}` - e.g. ```val func = { (a:Int, b:Int) =>        a + b}```<div class="se-preview-section-delimiter"></div>##variable params length------------------ style `def func(args: Type*) = {}`- e.g. <div class="se-preview-section-delimiter"></div>```def func(args: Int*) = {    (args :\ 0) {_+_}}
  • collection params transfer _*
func(1 to 10:_*)
0 0