Skip to content

Commit 22a4b9a

Browse files
Syntax Lookup: Mention partial application and order of labeled args
1 parent 82640a9 commit 22a4b9a

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

misc_docs/syntax/language_labeled_argument.mdx

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ When declaring a function, arguments can be prefixed with `~` which means that t
1212

1313
<CodeTab labels={["ReScript", "JS Output"]}>
1414

15-
```res
15+
```res prelude
1616
let calculateDistance = (~x1, ~y1, ~x2, ~y2) => {
1717
Math.sqrt((x1 -. x2) ** 2. +. (y1 -. y2) ** 2.)
1818
}
@@ -30,6 +30,39 @@ calculateDistance(6, 8, 3, 4);
3030

3131
</CodeTab>
3232

33+
Labeled arguments can be provided in any order:
34+
35+
<CodeTab labels={["ReScript", "JS Output"]}>
36+
37+
```res example
38+
calculateDistance(~x1=6., ~x2=3., ~y1=8., ~y2=4.)
39+
```
40+
41+
```js
42+
calculateDistance(6, 8, 3, 4);
43+
```
44+
45+
</CodeTab>
46+
47+
This also works together with partial application:
48+
49+
<CodeTab labels={["ReScript", "JS Output"]}>
50+
51+
```res example
52+
let calcY = calculateDistance(~x1=6., ~x2=3., ...)
53+
calcY(~y1=8., ~y2=4.)
54+
```
55+
56+
```js
57+
function calcY(none, extra) {
58+
return calculateDistance(6, none, 3, extra);
59+
}
60+
61+
calcY(8, 4);
62+
```
63+
64+
</CodeTab>
65+
3366
### References
3467

3568
* [Labeled Arguments](/docs/manual/latest/function#labeled-arguments)

0 commit comments

Comments
 (0)