Skip to content

Commit 05e789a

Browse files
Update misc_docs/syntax/operators_pipe.mdx
Co-authored-by: Patrick Ecker <[email protected]>
1 parent fcdaffc commit 05e789a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

misc_docs/syntax/operators_pipe.mdx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,37 @@ var message = dieRollMessage(Js_math.random_int(1, 6), "Marshall");
4040

4141
Which produces a message such as `Hello Marshall, you rolled a 3`.
4242

43+
You can also explicitly define the argument position of a piped value by using the `_` placeholder:
44+
45+
<CodeTab labels={["ReScript", "JS Output"]}>
46+
47+
```res example
48+
let logMsg = (user: string, datestr: string, msg: string): unit => {
49+
Js.log(`${user}|${datestr}|${msg}`)
50+
}
51+
52+
let datestr = "01-01-2021"
53+
let user = "admin"
54+
55+
// Here, we put the result of toUpperCase into the last position
56+
// denoted with an _
57+
Js.String2.toUpperCase("example message")->logMsg(user, datestr, _)
58+
```
59+
60+
```js
61+
function logMsg(user, datestr, msg) {
62+
console.log(user + "|" + datestr + "|" + msg);
63+
64+
}
65+
66+
var datestr = "01-01-2021";
67+
68+
var user = "admin";
69+
70+
logMsg(user, datestr, "example message".toUpperCase());
71+
```
72+
73+
</CodeTab>
4374
### References
4475

4576
* [Pipe](/docs/manual/latest/pipe)

0 commit comments

Comments
 (0)