-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction-call.jul
82 lines (67 loc) · 1.74 KB
/
function-call.jul
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
myFunction = (a b) => log(a b)
# 1. Argumente direkt übergeben
myFunction(1 2)
# 2. Argumente mit Parameternamen übergeben
myFunction(
a = 1
b = 2
)
# 2.1 Die Reihenfolge der Argumente ist egal (anders als bei 1.)
myFunction(
b = 2
a = 1
)
# 3. Argumente in einer List mit spread-Operator
myList = (1 2)
myFunction(...myList)
# 4. Argumente in einem Dictionary mit spread-Operator
myDictionary = (
a = 1
b = 2
)
myFunction(...myDictionary)
# 4.1 Die Reihenfolge der Argumente ist egal (anders als bei 3.)
myDictionary1 = (
b = 2
a = 1
)
myFunction(...myDictionary1)
# Bei 1. und 2. ist die Übergabe von nicht definierten Parametern nicht erlaubt.
# Bei 3. und 4. ist die Übergabe von nicht definierten Parametern erlaubt.
# Type Parametered Function
MyType = (
a: 1
b: 2
)
myFunction1 = (a: MyType) => log(§hi§)
myFunction1((a = 1 b = 2))
# äquivalent
typeFunction = MyType => log(§hi§)
typeFunction((a = 1 b = 2))
# TODO mit Parameternamen nicht erlaubt?
typeFunction(a = (a = 1 b = 2))
# Rest Parameter
restFunction = (...restParameter) => log(restParameter)
restFunction(1 2)
# äquivalent
restFunction(...(1 2))
# nicht äquivalent
restFunction((1 2))
# TODO mit Parameternamen nicht erlaubt?
restFunction(
a = 1
b = 2
)
# Rest Parameter getypt
# TODO rest type nur List oder auch Dictionary? bei rest Dictionary Parameternamen spreaden?
# bei rest type Tuple/DictionaryLiteral: feste Anzahl Argumente erzwingen?
restFunction2 = (...restParameter: MyType) => log(§hi§)
# äquivalent?
myFunction4 = (a: 1 b: 2) => log(§hi§)
# alias
aliasFn = (a1: Boolean = a b1 = b) => log(b1)
higherOrderFn = (fn: (a: Boolean b: Text) :> ()) => ()
higherOrderFn(aliasFn)
# nicht äquivalent
fn1 = (a: Boolean b: Text) => ()
fn2 = (b: Text a: Boolean) => ()