-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotes.txt
27 lines (16 loc) · 866 Bytes
/
notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
The rule of thumb is that a parameterless method that doesn’t modify the object has no parentheses.
a method b ===> a.method(b)
=== factorial ===
def factorial(n: BigInt): BigInt =
if(n == 0) 1 else n * factorial(n -1)
=== tail recursive factorial ===
def factorialTR(n: BigInt): BigInt = {
def loop(acc: BigInt, n: BigInt) : BigInt =
if(n == 0) acc else loop(acc * n, n - 1)
loop(1,n)
}
=== About Functional Programming ===
Functional programming is guided by two main ideas. The first idea is that functions are first-class values.
The second main idea of functional programming is that the operations of a program should map input values to output values rather than change data in place.
Another way of stating this second idea of functional programming is that methods should not have any side effects.
"=_" generates a setter (section 18.2)