Skip to content

Repository files navigation

Go Cantrips

Cantrips is a collection of useful functions in the Go Programming Language

Go Reference

What are Cantrips?

NOTE

/ ˈkɑn trɪp / noun

  1. chiefly Scotland: a magic spell; trick by sorcery.
  2. chiefly British: hocus-pocus.

Cantrips are small (magical) utility functions to achieve common tasks in Go. The name was inspired by Svelte 5's Runes and Baldur's Gate 3.

For example the Pop() function will remove the last element from a slice and return that element.

package main

import (
	"fmt"
	"github.com/banaaron/cantrips"
)

func main() {
	names := []string{"aaron", "chris", "drew"}
	n := cantrips.Pop(&names)
	fmt.Println(n)     // "drew"
	fmt.Println(names) // ["aaron", "chris"]

	// you can provide an index to remove an element at a specific index
	p := cantrips.Pop(&names, 1)
	fmt.Println(p)     // "chris"
	fmt.Println(names) // ["aaron"]
}

About

A collection of Go cantrips to make your life easier.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages