Scala中“=>”用法及含义
=> has several meanings in Scala, all related to its mathematical meaning as implication.
1. In a value, it introduces a function literal, or lambda. e.g. the bit inside the curly braces inList(1,2,3).map { (x: Int) => x * 2 }
2. In a type, with symbols on both sides of the arrow (e.g. A => T, (A,B) => T, (A,B,C) => T, etc.) it's sugar forFunction<n>[A[,B,...],T], that is, a function that takes parameters of typeA[,B...], and returns a value of type T.
2.1 Empty parens on the left hand side (e.g. () => T) indicate that the function takes no parameters (also sometimes called a "thunk");
2.2 Empty parens on the right hand side denote that it returns ()—the sole value of type Unit, whose name can also be written ()—confused yet? :)
A function that returns Unit is also known as a procedure, normally a method that's called only for its side effect.
3. In the type declaration for a method or function parameter, with no symbol on the left hand side (e.g.def f(param: => T)) it's a "by-name parameter", meaning that is evaluated every time it's used within the body of the function, and not before. Ordinary "by-value" parameters are evaluated before entry into the function/method.
4. In a case clause, they separate the pattern (and optional guard) from the result expression, e.g.case x => y.
参考链接:
1. https://stackoverflow.com/questions/6951895/what-does-and-mean-in-scala
2. http://www.aboutyun.com/thread-11934-1-1.html
Scala中“=>”用法及含义的更多相关文章
- Scala中apply的用法
Scala中的 apply 方法有着不同的含义, 对于函数来说该方法意味着调用function本身, 以下说明摘自Programming in Scala, 3rd Edition Every fun ...
- scala中常用但其他语言不常见的符号含义
本文旨在介绍Scala在其他语言中不太常见的符号含义,帮助理解Scala Code. 随着我对Scala学习的深入,我会不断增加该篇博文的内容. 修改记录 ----2016.11.23 新增scal ...
- Scala进阶之路-Scala中的枚举用法案例展示
Scala进阶之路-Scala中的枚举用法案例展示 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. Scala中的枚举值和Java中的枚举值有点差别,不过使用起来也都差大同小异,我这 ...
- Scala中_(下划线)的常见用法
Scala中_(下划线)的常见用法 地址:https://www.jianshu.com/p/0497583ec538
- Programming In Scala笔记-第十六章、Scala中的List
本章主要分析Scala中List的用法,List上可进行的操作,以及需要注意的地方. 一.List字面量 首先看几个List的示例. val fruit = List("apples&quo ...
- scala中常用特殊符号
参考资料: scala中常用但其他语言不常见的符号含义 Scala学习六:Scala中的特殊字符 =>(匿名函数) 参考文档:scala => 用法 匿名函数 => 匿名函数,在Sp ...
- TortoiseSVN中图标的含义
今天在使用svn时发现有好多不认识了,所以查了下svn帮助手册.借此总结了下 svn 中图标的含义 一个新检出的工作复本使用绿色的勾做重载.表示Subversion状态 正常. 在开始编辑一个文件后, ...
- C++中extern “C”含义深层探索
C++中extern “C”含义深层探索 extern “C” 是一个双向都需要用到的语法表示,就是说在cpp引用c头文件,或者c引用cpp文件时都需要用到.但extern “C” 永远只能在cpp引 ...
- java中printf中用法详解
目前printf支持以下格式: %c 单个字符 %d 十进制整数 %f 十进制浮点数 %o 八进制数 %s 字符串 %u 无符号十进制数 %x 十六进制数 %% 输出百分号% printf的格式控制的 ...
随机推荐
- CF 997E 解题报告
CF997E Good Subsegments 给你一个长度为\(n\)的排列 \(P\),定义一段子区间是好的,当且仅当这个子区间内的值构成了连续的一段.例如对于排列\(\{1,3,2\}\),\( ...
- 正确理解 LEAL (Load Effective Address) 指令
LEAL: leal S, D -> D ← &S 在 CSAPP (Computer Systems: A Programmer’s Perspective) 中,对 LE ...
- Java考试题之十
QUESTION 230 Given: 10. class One { 11. public One foo() { return this; } 12. } 13. class Two extend ...
- JS的对象原型
1.对象 1.1 语法 对象可以通过两种形式定义:声明(文字)形式和构造形式. 对象的文字语法: var myObj = { key : value //... }; 对象的构造语法: var myO ...
- fzyzojP3372 -- [校内训练20171124]博弈问题
对于每个点都要答案 还是异或 trie树合并石锤了 朴素枚举是O(n^2*17)的 怎么办呢? 我们发现合并的时候,一些部分的trie的子树还是不变的 改变的部分也就是合并的复杂度可以接受 鉴于大部分 ...
- python之旅:文件处理
一 文件操作及理论 1. 介绍 计算机系统分为:计算机硬件.操作系统.应用程序三部分我们用python或者其他程序,想要把数据永久的保存下来,就得写到硬盘里,但是应用程序是没有办法直接操作硬件的,这就 ...
- salt源码安装
salt是什么? 一种全新的基础设施管理方式,部署轻松,在几分钟内可运行起来,扩展性好,很容易管理上万台服务器,速度够快,服务器之间秒级通讯. salt底层采用动态的连接总线, 使其可以用于编配, 远 ...
- python 中__getitem__ 和 __iter__ 的区别
# -*- coding: utf-8 -*- class Library(object): def __init__(self): self.books = { 'title' : 'a', 'ti ...
- layoutSubviews中判断横竖屏
在ContentView中重写layoutSubviews方法,然后根据stausbar的方向判断当前视图的横竖屏.具体代码: -(void)layoutSubviews{ [super layout ...
- 数学建模 数据包络分析(DEA) Lingo实现
model: sets: dmu/../:lambda; !决策单元; inw/../:s1; !投入变量集; outw/../:s2; !产出变量集; inv(inw, dmu):x; !投入数据; ...