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
  • Wrapper Type Syntax
  • Working Example
Export as PDF
  1. Advanced Features

Wrapper Types

Wrapper types are equivalent to "Named Types" in Golang

Wrapper Type Syntax

wrapper <existing type to be wrapped> <Wrapper type name>

Working Example

package main

import "fmt" as fmt

wrapper Int Dollars

fun Dollars addDollars(Dollars currentAmount, Int amountToAdd) {
  return Dollars(((Int)(currentAmount)) + amountToAdd)
}

fun Unit printDollars(Dollars amount) {
  fmt.println(amount)
}

fun Unit main() {
  let dollarsIHave = Dollars(100)
  let newAmount = addDollars(dollarsIHave, 900)
  printDollars(newAmount)
}
package main

import fmt "fmt"

type dollars int

func addDollars(currentAmount dollars, amountToAdd int) dollars {

        return dollars((int(currentAmount)) + amountToAdd)

}

func printDollars(amount dollars) {
        fmt.Println(amount)

}

func main() {
        dollarsIHave := dollars(100)
        newAmount := addDollars(dollarsIHave, 900)
        printDollars(newAmount)
        // Eliminates any 'unused variable' errors
        _, _ = dollarsIHave, newAmount

}
1000

PreviousForce-Statements

Last updated 8 days ago

⚑
🌯