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
  • Method Syntax
  • Working Example
Export as PDF

Methods

PreviousAliasesNextLambdas

Last updated 8 days ago

Method Syntax

def <ReturnType> <methodName>(<ReceiverType receiverParamName>, Parameters) {
    <method body>
}

For syntax of Parameters -

Methods can be implemented only on wrapper types and structs.

Working Example

package main

import "fmt" as fmt
import "strconv" as strconv

struct Person {
  String FirstName
  String LastName
  Int Money
  Bool Happy  
}

def String getSummary(Person person) {
  let fullName = person.FirstName + " " + person.LastName
  return fullName + " has $" + strconv.Itoa(person.Money) + ". It is " + strconv.FormatBool(person.Happy) + " that he is happy."
}

fun Unit main() {
  let person = Person{FirstName = "John", LastName = "Doe", Money = 10000, Happy = true}
  fmt.println(person.getSummary())
}
package main

import fmt "fmt"
import strconv "strconv"

type person struct {
	happy     bool
	money     int
	lastName  string
	firstName string
}

func (person person) getSummary() string {
	fullName := person.firstName + " " + person.lastName

	// Eliminates any 'unused variable' errors
	_ = fullName
	return fullName + " has $" + strconv.Itoa(person.money) + ". It is " + strconv.FormatBool(person.happy) + " that he is happy."
}

func main() {
	person := person{firstName: "John", lastName: "Doe", money: 10000, happy: true}
	fmt.Println(person.getSummary())
	// Eliminates any 'unused variable' errors
	_ = person

}
John Doe has $10000. It is true that he is happy.
πŸ“Ž
Common placeholders throughout documentation