Skip to content

Commit

Permalink
Syntax Lookup: Mention partial application and order of labeled args
Browse files Browse the repository at this point in the history
  • Loading branch information
fhammerschmidt committed Jun 28, 2024
1 parent 82640a9 commit 22a4b9a
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion misc_docs/syntax/language_labeled_argument.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ When declaring a function, arguments can be prefixed with `~` which means that t

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

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

</CodeTab>

Labeled arguments can be provided in any order:

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

```res example
calculateDistance(~x1=6., ~x2=3., ~y1=8., ~y2=4.)
```

```js
calculateDistance(6, 8, 3, 4);
```

</CodeTab>

This also works together with partial application:

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

```res example
let calcY = calculateDistance(~x1=6., ~x2=3., ...)
calcY(~y1=8., ~y2=4.)
```

```js
function calcY(none, extra) {
return calculateDistance(6, none, 3, extra);
}

calcY(8, 4);
```

</CodeTab>

### References

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

0 comments on commit 22a4b9a

Please sign in to comment.