Skip to content
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

Add syntax lookup pipe operator #192

Merged
merged 5 commits into from
Jan 16, 2021
Merged
Changes from 2 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
45 changes: 45 additions & 0 deletions misc_docs/syntax/operators_pipe.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
id: "pipe"
keywords: ["pipe", "operator", "function", "argument"]
name: "->"
summary: "This is the `pipe` operator."
category: "operators"
---

The `->` operator provides an convenient syntax for passing a value into a function. Typically it's used to pass a value into a function as its first argument.
kevanstannard marked this conversation as resolved.
Show resolved Hide resolved

### Example

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

```res
let dieRoll = size => {
Js.Math.random_int(1, size)
}

let dieRollMessage = (value, name) => {
"Hi " ++ name ++ ", you rolled a " ++ Js.Int.toString(value)
}

let message = dieRoll(6)->dieRollMessage("Marshall")
```

```js
function dieRoll(size) {
return Js_math.random_int(1, size);
}

function dieRollMessage(value, name) {
return "Hi " + name + ", you rolled a " + value.toString();
}

var message = dieRollMessage(Js_math.random_int(1, 6), "Marshall");
```

</CodeTab>

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

kevanstannard marked this conversation as resolved.
Show resolved Hide resolved
### References

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