Skip to content

Latest commit

 

History

History
45 lines (32 loc) · 977 Bytes

operators_pipe.mdx

File metadata and controls

45 lines (32 loc) · 977 Bytes
id keywords name summary category
pipe
pipe
operator
function
argument
->
This is the `pipe` operator.
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.

Example

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

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")
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");

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

References