Skip to content

Commit ad388a5

Browse files
authored
Merge pull request #247 from kevanstannard/syntax-lookup-function-and-uncurried-function
Syntax lookup: function / uncurried function
2 parents f59dca7 + 9f09441 commit ad388a5

File tree

3 files changed

+72
-11
lines changed

3 files changed

+72
-11
lines changed

misc_docs/syntax/function_uncurried.mdx

-11
This file was deleted.
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
id: "function"
3+
keywords: ["function"]
4+
name: "() => {}"
5+
summary: "This is a `function`."
6+
category: "languageconstructs"
7+
---
8+
9+
Functions are declared with arguments in parentheses, an arrow, and a return expression.
10+
11+
### Example
12+
13+
<CodeTab labels={["ReScript", "JS Output"]}>
14+
15+
```res
16+
let greet = (name: string) => {
17+
"Hello " ++ name
18+
}
19+
```
20+
21+
```js
22+
function greet(name) {
23+
return "Hello " + name;
24+
}
25+
```
26+
27+
</CodeTab>
28+
29+
### References
30+
31+
* [Function](/docs/manual/latest/function)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
id: "uncurried-function"
3+
keywords: ["function", "uncurried"]
4+
name: "(.) => {}"
5+
summary: "This is an `uncurried function`."
6+
category: "languageconstructs"
7+
---
8+
9+
ReScript functions are curried by default, however in certain cases you may need an uncurried function. In these cases we add a `.` in the argument list.
10+
11+
When calling uncurried functions, we must also include a `.` in the argument list.
12+
13+
### Example
14+
15+
<CodeTab labels={["ReScript", "JS Output"]}>
16+
17+
```res
18+
let add = (. x, y) => {
19+
x + y
20+
}
21+
22+
let withCallback = (cb: (. int) => unit) => {
23+
cb(. 1)
24+
}
25+
```
26+
27+
```js
28+
function add(x, y) {
29+
return (x + y) | 0;
30+
}
31+
32+
function withCallback(cb) {
33+
return cb(1);
34+
}
35+
```
36+
37+
</CodeTab>
38+
39+
### References
40+
41+
- [Uncurried Function](/docs/manual/latest/function#uncurried-function)

0 commit comments

Comments
 (0)