@@ -13,20 +13,60 @@ let component = () =>
13
13
</a >
14
14
</h2 >
15
15
<hr />
16
- <h3 className= "mt-4 mb-2 font-hairline" > "Functions" -> Utils . str </h3 >
16
+ <h3 className= "mt-4 mb-2 font-hairline" > "Functions and their signatures " -> Utils . str </h3 >
17
17
<hr />
18
18
<pre > <code > "let add = (x: int, y: int) => x + y;" -> Utils . str </code > </pre >
19
19
<hr />
20
- <pre > <code > "let addComponents = ((x: int, y: int)) => x + y;" -> Utils . str </code > </pre >
21
- <hr />
20
+ <p className= "my-2 font-hairline" >
21
+ "Labeled arugments with defined types, \" optional\" values, note: partial application" -> Utils . str
22
+ </p >
22
23
<pre > <code > "let add = (~x: option(int)=?, ~y: option(int)=?, ()) => ...;" -> Utils . str </code > </pre >
23
24
<hr />
25
+ <p className= "my-2 font-hairline" > "Labeled arugments with defined types and default values" -> Utils . str </p >
24
26
<pre > <code > "let add = (~x: int=0, ~y: int=0, ()) => x + y;" -> Utils . str </code > </pre >
27
+ <hr />
28
+ <p className= "my-2 font-hairline" > "Recurision" -> Utils . str </p >
29
+ <pre >
30
+ <code >
31
+ "let rec summarize = (l: list(int)) => switch l {
32
+ | [] => 0
33
+ | [head, ...tail] => head + summarize(tail)
34
+ };"
35
+ -> Utils . str
36
+ </code >
37
+ </pre >
38
+ <p className= "my-2 font-hairline" > "Reverse-application or pipe operator" -> Utils . str </p >
39
+ <pre > <code > "|>" -> Utils . str </code > </pre >
40
+ <p className= "my-2 font-hairline" >
41
+ "The operator |> is called reverse-application operator or pipe operator. It lets you chain function calls: x |> f is the same as f(x). That may not look like much, but it is quite useful when combining function calls."
42
+ -> Utils . str
43
+ </p >
44
+ <pre >
45
+ <code >
46
+ "[4, 2, 1, 3, 5]
47
+ |> List.map(x => x + 1)
48
+ |> List.filter(x => x < 5)
49
+ |> List.sort(compare);" -> Utils . str
50
+ </code >
51
+ </pre >
52
+ <hr />
53
+ <a className= "my-2 font-hairline" href= "https://bucklescript.github.io/docs/en/pipe-first" >
54
+ "BuckleScript has a special |. (or -> for Reason) pipe syntax for dealing with various situations. This operator has many uses."
55
+ -> Utils . str
56
+ </a >
57
+ <pre > <code > "a
58
+ ->foo(b)
59
+ ->bar;
60
+
61
+ // is equal to
62
+
63
+ bar(foo(a, b));" -> Utils . str </code > </pre >
25
64
<hr />
26
65
<h3 className= "my-2 font-hairline" > "Variants & Pattern Matching" -> Utils . str </h3 >
27
66
<hr />
28
67
<pre > <code > "type color = Red | Orange | Yellow | Green | Blue | Purple;" -> Utils . str </code > </pre >
29
68
<hr />
69
+ <p className= "my-2 font-hairline" > "Lookup table, similar to JS" -> Utils . str </p >
30
70
<pre >
31
71
<code >
32
72
"let stringOfColor = (c: color) => switch c {
@@ -40,11 +80,17 @@ let component = () =>
40
80
-> Utils . str
41
81
</code >
42
82
</pre >
83
+ <a className= "my-2 font-hairline" href= "http://reasonmlhub.com/exploring-reasonml/ch_records.html" >
84
+ "Could also return records i.e {x: 12, y: -2};" -> Utils . str
85
+ </a >
43
86
<hr />
87
+ <p className= "my-2 font-hairline" > "Prefer variants over booleans since:" -> Utils . str </p >
44
88
<pre >
45
89
<code >
46
90
"type includeDetails = ShowEverything | HideDetails;
91
+
47
92
let stringOfContact = (~levelOfDetail: includeDetails, c: contact) => ...;
93
+
48
94
let str = stringOfContact(~levelOfDetail=ShowEverything, myContact);"
49
95
-> Utils . str
50
96
</code >
@@ -58,23 +104,15 @@ let str = stringOfContact(~levelOfDetail=ShowEverything, myContact);"
58
104
<li className= "my-2 font-hairline" > "+ It is easy to add more modes later on." -> Utils . str </li >
59
105
</ul >
60
106
<hr />
107
+ <p className= "my-2 font-hairline" > "Composing types" -> Utils . str </p >
61
108
<pre >
62
109
<code >
63
110
"type point = Point(float, float);
111
+
64
112
type shape =
65
113
| Rectangle(point, point)
66
114
| Circle(point, float);"
67
115
-> Utils . str
68
116
</code >
69
117
</pre >
70
- <hr />
71
- <pre >
72
- <code >
73
- "let rec summarize = (l: list(int)) => switch l {
74
- | [] => 0
75
- | [head, ...tail] => head + summarize(tail)
76
- };"
77
- -> Utils . str
78
- </code >
79
- </pre >
80
- </div >;
118
+ </div >;
0 commit comments