Skip to content

Commit 43e81dc

Browse files
author
Kevan Stannard
committed
Update unwrap decorator
1 parent 3a779bf commit 43e81dc

File tree

1 file changed

+10
-23
lines changed

1 file changed

+10
-23
lines changed

misc_docs/syntax/decorator_unwrap.mdx

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,10 @@ summary: "This is the `@unwrap` decorator."
66
category: "decorators"
77
---
88

9-
The `@unwrap` decorator may be used when binding to external functions that accept multiple types for an argument.
9+
The `@unwrap` decorator may be used when binding to external functions
10+
that accept multiple types for an argument.
1011

11-
Consider the following JavaScript function:
12-
13-
```js
14-
function padLeft(padding, str) {
15-
if (typeof padding === "number") {
16-
return " ".repeat(padding) + str;
17-
}
18-
if (typeof padding === "string") {
19-
return padding + str;
20-
}
21-
throw new Error("Expected padding to be number or string");
22-
}
23-
```
24-
Note how `padding` can be either a number or a string.
25-
26-
Here is how you'd bind to this function:
12+
### Example
2713

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

@@ -33,16 +19,17 @@ Here is how you'd bind to this function:
3319
string
3420
) => string = "padLeft";
3521
36-
let _ = padLeft(#Int(7), "eleven");
37-
let _ = padLeft(#Str("7"), "eleven");
22+
let result1 = padLeft(#Int(7), "eleven");
23+
let result2 = padLeft(#Str("7"), "eleven");
3824
```
3925

4026
```js
41-
padLeft(7, "eleven");
42-
43-
padLeft("7", "eleven");
27+
var result1 = padLeft(7, "eleven");
28+
var result2 = padLeft("7", "eleven");
4429
```
4530

4631
</CodeTab>
4732

48-
Review the JavaScript output and note how `@unwrap` simply unwraps the polymorphic variant constructor.
33+
### References
34+
35+
* [Modeling Polymorphic Function](/docs/manual/latest/bind-to-js-function#modeling-polymorphic-function)

0 commit comments

Comments
 (0)