scala中命名参数函数

具有命名参数的函数 (Functions with named arguments )

A function is Scala can take multiple arguments. These arguments are traditionally called in sequence while calling a function. But in Scala programming, the program is given the power to alter the traditional sequence of arguments. Scala provides its users named arguments these are used to change the order of using arguments at call.

一个函数是Scala可以接受多个参数。 这些参数通常在调用函数时按顺序调用。 但是在Scala编程中,程序有权更改传统的参数顺序。 Scala为用户提供了命名参数,这些参数用于更改调用时使用参数的顺序。

Suppose a function that has two variables var1 and var2. If we want to initialize var2 first then the following syntax is used.

假设一个函数具有两个变量var1和var2 。 如果我们要首先初始化var2,则使用以下语法。

Syntax:

句法:

    functionName ( var2 = value2, var2 = value1 );

Explanation:

说明:

This will pass the value2 to the second argument in the list. And value1 in the first argument in the list.

这会将value2传递给列表中的第二个参数。 并在列表中的第一个参数中使用value1。

Example:

例:

object Demo {def sub( a:Int, b:Int ) = {println("Substraction = " + (a-b) );
}
def main(args: Array[String]) {println("The fucntion is called using named function call")
sub(b = 5, a = 7);
}
}

Output

输出量

The fucntion is called using named function call
Substraction = 2

Explanation:

说明:

This code displays how to use named arguments in Scala? The code initializes a function named sub(), it expects two arguments and substracts second from first. At function call, the arguments are filled using the names that initialize them in the order the programmer wants.

此代码显示如何在Scala中使用命名参数? 该代码初始化了一个名为sub()的函数,它需要两个参数并从第一个减去第二个。 在函数调用时,将使用按程序员想要的顺序对其进行初始化的名称来填充参数。

翻译自: https://www.includehelp.com/scala/functions-with-named-arguments-in-scala.aspx

scala中命名参数函数

scala中命名参数函数_Scala中带有命名参数的函数相关推荐

  1. scala中命名参数函数_Scala中的命名参数和默认参数值

    scala中命名参数函数 In this post, we are going to discuss the following two important concepts in Scala abo ...

  2. scala 函数中嵌套函数_Scala中的VarArgs函数和@varargs批注

    scala 函数中嵌套函数 In this post, we are going to discuss about Functions with Var-Args (Variable Number O ...

  3. scala中的高阶函数_Scala中的高阶函数(HOF)

    scala中的高阶函数 Higher Order Functions (HOF) in Scala are the very core of this functional programming l ...

  4. scala重载无参构造方法_Scala中的无参数方法

    scala重载无参构造方法 Scala无参数方法 (Scala parameterless method) A method which accepts no parameters from the ...

  5. scala部分应用函数_Scala中的部分函数

    scala部分应用函数 Scala部分功能 (Scala partial functions) A partial function is a function that returns values ...

  6. scala 函数中嵌套函数_Scala中的嵌套函数 用法和示例

    scala 函数中嵌套函数 Scala中的嵌套函数 (Nested functions in Scala) A nested function is defined as a function whi ...

  7. scala 字符串函数_Scala中的字符串chomp(或chop)函数

    scala 字符串函数 剁或剁弦 (Chop or Chomp string) It is used to chop off the end of line characters. For this ...

  8. html绑定带有形参的函数,Python中函数参数类型和参数绑定

    参数类型 Python函数的参数类型一共有五种,分别是: POSITIONAL_OR_KEYWORD(位置参数或关键字参数) VAR_POSITIONAL(可变参数) KEYWORD_ONLY(关键字 ...

  9. python sep函数_Python中带有print()函数的sep参数

    python sep函数 sep parameter stands for separator, it uses with the print() function to specify the se ...

最新文章

  1. 下一个10年,解决问题靠“大脑”
  2. [CF.Skills]播放嵌入资源的声音文件
  3. 2、创建视图(CREATE VIEW)
  4. 怎么写自己的CMakeLists.txt--二
  5. Spark算子:RDD键值转换操作(2)–combineByKey、foldByKey
  6. 因子分析(FA)算法简述
  7. matlab高通滤波函数,巴特沃斯高通滤波器—matlab实现
  8. 机器学习项目-金融反欺诈模型
  9. 解决VirtualBox配置静态ip和连外网的问题
  10. java 如何获取当前时间到夜晚12点的毫秒差值
  11. WPF游戏开发——小鸡快跑
  12. 风骚的操作:区块链监控个人账户即时在线充值
  13. 访问hfds报错AccessControlException
  14. 我们为什么这么拼?(转载自微信)
  15. PostgreSQL JIT(Just-In-Time Compilation)With LLVM 的实现原理
  16. [BUUCTF-pwn] qwb2018_opm
  17. 序列自相关矩阵的计算和分析
  18. postgresql增、删、改、查语句
  19. php制作医院预约电子就诊卡
  20. CTF题记——计划第一周

热门文章

  1. 计算机算法知识总结,移动笔试知识点之--计算机类-数据结构与算法知识点总结.pdf...
  2. 某高校2006年招收学生3千人c语言,C语言程序设计例题
  3. 如何查看mysql的gtid_汇总丨MySQL GTID技术点,看这一篇就够了!
  4. node.js 搭建http调取 mysql数据库中的值
  5. 小程序 循环中有多个input,怎么获取每个input输入框的值
  6. Tmux: 打造精致与实用并存的终端
  7. 最大连续子序列----DP动态规划
  8. TMS320DM642学习----第一篇(硬件连接)
  9. Day-6:创建计算字段
  10. Ajax应用需要注意的事项