Skip to content

Add example how to match on two items in a list pattern #1007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions pages/docs/manual/v12.0.0/array-and-list.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,20 @@ var anotherList = {
let message =
switch myList {
| list{} => "This list is empty"
| list{first, second, ...rest} => "The list two items and a potenial remainder of items"
| list{a, ...rest} => "The head of the list is the string " ++ Int.toString(a)
}
```
```js
var message = myList
? "The head of the list is the string " + (1).toString()
: "This list is empty";
let message = myList !== 0 ? (
({
hd: 2,
tl: {
hd: 3,
tl: /* [] */0
}
}) !== 0 ? "The list two items and a potenial remainder of items" : "The head of the list is the string " + (1).toString()
) : "This list is empty";
```

</CodeTab>
32 changes: 16 additions & 16 deletions pages/docs/react/latest/router.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ let make = () => {
let url = RescriptReactRouter.useUrl()

switch url.path {
| list{"user", id} => <User id />
| list{"user", id, ..._} => <User id />
| list{} => <Home/>
| _ => <PageNotFound/>
}
Expand All @@ -90,28 +90,28 @@ import * as Home from "./Home.res.js";
import * as NotFound from "./NotFound.res.js";

function App(Props) {
var url = RescriptReactRouter.useUrl(undefined, undefined);
var match = url.path;
if (!match) {
return React.createElement(Home.make, {});
let url = RescriptReactRouter.useUrl(undefined, undefined);
let match = url.path;
if (match === 0) {
return JsxRuntime.jsx(Home, {});
}
if (match.hd === "user") {
var match$1 = match.tl;
if (match$1 && !match$1.tl) {
return React.createElement(User.make, {
id: match$1.hd
});
}

if (match.hd !== "user") {
return JsxRuntime.jsx(NotFound, {});
}
let match$1 = match.tl;
if (match$1 !== 0 && match$1.tl === 0) {
return JsxRuntime.jsx(User, {
id: match$1.hd
});
} else {
return JsxRuntime.jsx(NotFound, {});
}
return React.createElement(NotFound.make, {});
}

var make = App;

export {
make ,

make,
}
```

Expand Down