cantrips

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2024 License: GPL-3.0 Imports: 5 Imported by: 0

README

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"]
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pop

func Pop[T any](slice *[]T, index ...int) (popped T)

Pop removes last element from a slice.

Returns the removed element.

slice: pointer to a slice of any type

index (optional): index of the element you wish to removed.

func ReverseString added in v0.1.0

func ReverseString(input string) string

ReverseString reverses a string

func SortKeys added in v0.1.0

func SortKeys[Key ordered, Value any](input map[Key]Value, reverse ...bool) (keys []Key)

SortKeys returns a slice of keys in ascending order.

input: a map with int, float, or string keys

reverse: keys will be in descending order if set to true

func ToLower added in v0.2.0

func ToLower(input string) string

func ToTitle added in v0.2.0

func ToTitle(input string) string

func ToUpper added in v0.2.0

func ToUpper(input string) string

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL