Skip to content

Commit db8b71e

Browse files
authored
Add example how to match on two items in a list pattern (#1007)
1 parent 0f2eaa4 commit db8b71e

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

pages/docs/manual/v12.0.0/array-and-list.mdx

+10-3
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,20 @@ var anotherList = {
207207
let message =
208208
switch myList {
209209
| list{} => "This list is empty"
210+
| list{first, second, ...rest} => "The list two items and a potenial remainder of items"
210211
| list{a, ...rest} => "The head of the list is the string " ++ Int.toString(a)
211212
}
212213
```
213214
```js
214-
var message = myList
215-
? "The head of the list is the string " + (1).toString()
216-
: "This list is empty";
215+
let message = myList !== 0 ? (
216+
({
217+
hd: 2,
218+
tl: {
219+
hd: 3,
220+
tl: /* [] */0
221+
}
222+
}) !== 0 ? "The list two items and a potenial remainder of items" : "The head of the list is the string " + (1).toString()
223+
) : "This list is empty";
217224
```
218225

219226
</CodeTab>

pages/docs/react/latest/router.mdx

+16-16
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ let make = () => {
7676
let url = RescriptReactRouter.useUrl()
7777
7878
switch url.path {
79-
| list{"user", id} => <User id />
79+
| list{"user", id, ..._} => <User id />
8080
| list{} => <Home/>
8181
| _ => <PageNotFound/>
8282
}
@@ -90,28 +90,28 @@ import * as Home from "./Home.res.js";
9090
import * as NotFound from "./NotFound.res.js";
9191

9292
function App(Props) {
93-
var url = RescriptReactRouter.useUrl(undefined, undefined);
94-
var match = url.path;
95-
if (!match) {
96-
return React.createElement(Home.make, {});
93+
let url = RescriptReactRouter.useUrl(undefined, undefined);
94+
let match = url.path;
95+
if (match === 0) {
96+
return JsxRuntime.jsx(Home, {});
9797
}
98-
if (match.hd === "user") {
99-
var match$1 = match.tl;
100-
if (match$1 && !match$1.tl) {
101-
return React.createElement(User.make, {
102-
id: match$1.hd
103-
});
104-
}
105-
98+
if (match.hd !== "user") {
99+
return JsxRuntime.jsx(NotFound, {});
100+
}
101+
let match$1 = match.tl;
102+
if (match$1 !== 0 && match$1.tl === 0) {
103+
return JsxRuntime.jsx(User, {
104+
id: match$1.hd
105+
});
106+
} else {
107+
return JsxRuntime.jsx(NotFound, {});
106108
}
107-
return React.createElement(NotFound.make, {});
108109
}
109110

110111
var make = App;
111112

112113
export {
113-
make ,
114-
114+
make,
115115
}
116116
```
117117

0 commit comments

Comments
 (0)