Syntax Lookup
Enter some language construct you want to know more about.
This is the pipe operator.
The ->
operator passes a value into the first argument position of a function. Typically it's used to chain multiple function calls together in a "pipeline like" fashion.
Example
Which produces a message such as Hello Marshall, you rolled a 3
.
You can also explicitly define the argument position of a piped value by using the _
placeholder:
let logMsg = (user: string, datestr: string, msg: string): unit => {
Console.log(`${user}|${datestr}|${msg}`)
}
let datestr = "01-01-2021"
let user = "admin"
// Here, we put the result of toUpperCase into the last position
// denoted with an _
String.toUpperCase("example message")->logMsg(user, datestr, _)