[WIP] Scala 学习 📒
- Dominant language
- No language data
- Stars
- 7
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
## 1. 函数和方法的区别
def 是方法 =。=
http://stackoverflow.com/a/2530007/4568509
## 2. 方法调用
### 2.1 ()
``` scala
def a(x: Int) = x + 1
a(2)
```
### 2.2 {}
``` scala
a{2}
```
### 2.3 逃~
``` scala
// 因为:
{2} == 2
(2) == 2
// 所以下面都相当于 a(2):
a((((2))))
a{{{{2}}}}
a{{((2))}}
a(({{2}}))
```
### 2.4 省略括号
参见 #3
## 3. 括号的省略
### 3.1 无参方法
``` scala
def a() = 1
a() // 1
a // 1
```
### 3.2 方法调用
无括号调用时必须得省略小数点
``` scala
class A {
def b(x: Int) = x + 1
}
val a = new A
a.b(2) // 3
a.b 2 // error 必须得省略小数点
a b 2 // 3
```
## 4. 伟大的 _
### 4.1 方法转函数
``` scala
class A {
def b(x: Int) = x + 1
}
val a = new A
a.b _ // Int => Int =
a.b(_) // function1 可以这样转
a.b(_, _) // function2 可以这样转,trait FunctionN 同理
```
### 4.2 Partial application
``` scala
def adder(a: Int, b: Int) => a + b
val add2 = adder(_: Int, 2)
add2(1) // 3
```
你可以部分应用参数列表中的任意参数,而不仅仅是最后一个。
Contributor guide
No contributing guide indexed for this repository
Research direction
The issue contains Chinese-language Scala learning notes and examples but does not name a repository file, test, or concrete documentation change. Start by determining whether these notes belong in the blog and what content or structure is expected; done is not defined by the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 15/100