Gauntlet Documentation
  • 🏠Welcome
  • πŸ…Getting Started
    • 🧠Introduction To Gauntlet
  • ‼️Read before Proceeding
  • ⬇️Installation
  • πŸ‘¨β€πŸ’»VSCode Extension
  • πŸ“šBasics
    • πŸ’¨Running Gauntlet
    • πŸ“„File Setup & Hello World
  • πŸ” Scope Variables
  • πŸ–ΌοΈConstants
  • 🧩Functions
  • ↔️If Statements
  • πŸ”‘Ternary Operator
  • πŸ’ Switch-Case
  • πŸ“©Select-Case
  • ➰Loops
  • πŸ“Structs
  • 🧱Interfaces
  • πŸͺͺAliases
  • πŸ“ŽMethods
  • πŸ¦™Lambdas
  • πŸ•ΈοΈMiscellaneous
  • ⚑Advanced Features
    • πŸ”€When-Cases
    • 🚰Pipes
    • ⁉️Try-Statements
    • 🎭Force-Statements
    • 🌯Wrapper Types
Powered by GitBook
On this page
  • Pipe Syntax
  • Working Example
Export as PDF
  1. Advanced Features

Pipes

Pipe Syntax

expr => someFunctionCall(<args with at least one underscore>)

The pipe (=> ) takes the expression on the left and "pipes" it into the function right, wherever there are underscores.

For every underscore you use, a new instance of the left-hand expression will be made. For instance, myExpr β‡’ someFunction(_, _) turns into someFunction(myExpr, myExpr). This many result in unwanted side-effects.

Working Example

package main

import "fmt" as fmt

fun Int add(Int num, Int addend) {
  return num + addend
}

fun Int subtract(Int num, Int subtrahend) {
  return num - subtrahend
}

fun Int multiply(Int num, Int multiplier) {
  return num * multiplier
}

fun Int divide(Int num, Int divisor) {
  return num / divisor
}

fun Unit main() {
  10
  => add(_, 10)
  => add(_, 30)
  => divide(_, 2)
  => subtract(_, 5)
  => divide(_, 2)
  => multiply(_, 10)
  => fmt.println(_)
}
package main

import fmt "fmt"

func add(num int, addend int) int {

	return num + addend

}

func subtract(num int, subtrahend int) int {

	return num - subtrahend

}

func multiply(num int, multiplier int) int {

	return num * multiplier

}

func divide(num int, divisor int) int {

	return num / divisor

}

func main() {
	fmt.Println(multiply(divide(subtract(divide(add(add(10, 10), 30), 2), 5), 2), 10))

}
100

PreviousWhen-CasesNextTry-Statements

Last updated 8 days ago

⚑
🚰