Algorithms Not in Go Language Standard library
As the name implies, there are (or were at the time of writing) commonly required operations/algorithms that are not provided in the language standard library. This library is a slowly growing collection of such things. (As of time of writing it does not contain any generic, but the plan is to sort that in the coming weeks.)
As an example, the standard library's strings package provides the following functions to split a string into []string:
func Split(s, sep string) []string
func SplitN(s, sep string, n int) []string
func SplitAfter(s, sep string) []string
func SplitAfterN(s, sep string, n int) []stringANGoLS provides a bunch of additional split functions that provide more expressiveness and/or functionality not possible with the standard library functions, including:
func SplitAfterByte(s string, sep byte) []string
func SplitAfterByteN(s string, sep byte, ix int) []string
func SplitAfterRune(s string, sep rune) []string
func SplitAfterRuneN(s string, sep rune, ix int) []string
func SplitAfterAny(s, chars string) []string
func SplitAfterAnyN(s, chars string, ix int) []string
func SplitAfterAnyBytes(s string, seps []byte) []string
func SplitAfterAnyBytesN(s string, seps []byte, ix int) []string
func SplitAfterAnyRunes(s string, seps []rune) []string
func SplitAfterAnyRunesN(s string, seps []rune, ix int) []stringgo get "github.com/synesissoftware/ANGoLS"import (
angols_slices "github.com/synesissoftware/ANGoLS/slices"
angols_strings "github.com/synesissoftware/ANGoLS/strings"
)Modelled after Ruby's Enumerable#collect(), these functions provide for transforming a slice of a given type with given values into a same-sized slice of a given type with transformed values.
// in "github.com/synesissoftware/ANGoLS/slices"
// This function maps an input slice of T[] to an output slice of []T.
func CollectSlice[T any](input_slice []T, collector func(index int, input_item *T) (T, error)) ([]T, error)
// This function maps an input slice of []int to an output slice of []int.
func CollectSliceOfInt(input_slice []int, collector func(input_item int) int) (result_slice []int)
// This function maps an input slice of []N to an output slice of []N, where
// N is any integer type.
func CollectSliceOfInteger[N int8 | int16 | int32 | int64 | int | uint8 | uint16 | uint32 | uint64 | uint | uintptr](input_slice []N, collector func(input_item N) N) (result_slice []N)
// This function maps an input slice of []float64 to an output slice of
// []float64.
func CollectSliceOfFloat64(input_slice []float64, collector func(input_item float64) float64) (result_slice []float64)
// This function maps an input slice of []string to an output slice of
// []string.
func CollectSliceOfString(input_slice []string, collector func(input_item string) string) (result_slice []string)
// This function maps an input slice of []T to an output slice of []string.
func CollectSliceIntoStringSlice[T any](input_slice []T, collector func(input_item *T) (string, error)) ([]string, error)Functions for evaluating equality between slices, in terms of both length and contents (values and ordering).
// in "github.com/synesissoftware/ANGoLS/slices"
// Indicates whether two []int slices have the same size, contents, and
// order.
func EqualSliceOfInt(lhs, rhs []int) bool
// Indicates whether two []uint slices have the same size, contents, and
// order.
func EqualSliceOfUint(lhs, rhs []uint) bool
func EqualSliceOfInteger[N int8 | int16 | int32 | int64 | int | uint8 | uint16 | uint32 | uint64 | uint | uintptr](lhs, rhs []int) bool
// Indicates whether two []float64 slices have the same size, contents, and
// order.
func EqualSliceOfFloat64(lhs, rhs []float64) bool
// Indicates whether two []string slices have the same size, contents, and
// order.
func EqualSliceOfString(lhs, rhs []string) bool
func EqualSlice(lhs, rhs any) boolFunctions for generating slices of a given size and type from a generator function.
// in "github.com/synesissoftware/ANGoLS/slices"
// Creates a slice of a given size and populates its values with the given
// generator (which may be nil).
func GenerateSliceOfInt(size int, generator func(index int) (result int, err error)) (result []int, err error)
// Creates a slice of a given size and populates its values with the given
// generator (which may be nil).
func GenerateSliceOfUint(size int, generator func(index int) (result uint, err error)) (result []uint, err error)
// Creates a slice of a given size and populates its values with the given
// generator (which may be nil).
func GenerateSliceOfString(size int, generator func(index int) (result string, err error)) (result []string, err error)Modelled after Ruby's Enumerable#select(), these functions provide for selecting elements of a given slice of a given type into a new slice of the given type.
// in "github.com/synesissoftware/ANGoLS/slices"
func SelectSliceOfInt(input_slice []int, selector func(index int, input_item int) (bool, error)) ([]int, error)
func SelectSliceOfUint(input_slice []uint, selector func(index int, input_item uint) (bool, error)) ([]uint, error)
func SelectSliceOfInteger[N int8 | int16 | int32 | int64 | int | uint8 | uint16 | uint32 | uint64 | uint | uintptr](input_slice []N, selector func(index int, input_item N) (bool, error)) ([]N, error)
func SelectSliceOfString(input_slice []string, selector func(index int, input_item string) (bool, error)) ([]string, error)// in "github.com/synesissoftware/ANGoLS/strings"
// Returns a copy of s with all uppercase ASCII letters converted to their
// lowercase equivalents. Non-ASCII bytes and non-uppercase letters are left
// unchanged.
//
// The prime use-case for this function is when dealing with strings that
// are known to contain only ASCII and a faster conversion than is provided
// by the standard `ToLower()` is desired.
func ASCIIToLower(s string) string
// Returns a copy of s with all lowercase ASCII letters converted to their
// uppercase equivalents. Non-ASCII bytes and non-lowercase letters are left
// unchanged.
//
// The prime use-case for this function is when dealing with strings that
// are known to contain only ASCII and a faster conversion than is provided
// by the standard `ToUpper()` is desired.
func ASCIIToUpper(s string) string// Finds the index of the given substring in the given string, starting from
// the position after the given index. -1 is returned if the find is not
// successful.
//
// To search from the start of the string, specify the value -1 for the
// index. Any index value less than -1 will be treated as if -1 specified.
// Any index value greater than the size of the string will result in a
// return value of -1.
//
// The returned value reflects the position of the found substring relative
// to the start of the string, not from the index.
func IndexAfter(s string, sf string, ix int) int
// Finds the index of the first instance of any character in chars, starting
// from the position after the given index. -1 is returned if the find is
// not successful.
//
// To search from the start of the string, specify the value -1 for the
// index. Any index value less than -1 will be treated as if -1 specified.
// Any index value greater than the size of the string will result in a
// return value of -1.
//
// The returned value reflects the position of the found character relative
// to the start of the string, not from the index.
func IndexAnyAfter(s string, chars string, ix int) int
// Finds the index of the given byte in the given string, starting from the
// position after the given index. -1 is returned if the find is not
// successful.
//
// To search from the start of the string, specifying the value -1 for the
// index. Any index value less than -1 will be treated as if -1 specified.
// Any index value greater than the size of the string will result in a
// return value of -1.
//
// The returned value reflects the position of the found byte relative to
// the start of the string, not from the index.
func IndexByteAfter(s string, c byte, ix int) int
// Finds the index of a character identified by the given function, starting
// from the position after the given index. -1 is returned if the find is
// not successful.
//
// To search from the start of the string, specifying the value -1 for the
// index. Any index value less than -1 will be treated as if -1 specified.
// Any index value greater than the size of the string will result in a
// return value of -1.
//
// The returned value reflects the position of the identified character
// relative to the start of the string, not from the index.
func IndexFuncAfter(s string, f func(rune) bool, ix int) int
// Finds the index of the first instance of any character not in chars,
// starting from the position after the given index. -1 is returned if the
// find is not successful.
//
// To search from the start of the string, specify the value -1 for the
// index. Any index value less than -1 will be treated as if -1 specified.
// Any index value greater than the size of the string will result in a
// return value of -1.
//
// The returned value reflects the position of the found character relative
// to the start of the string, not from the index.
func IndexNotAnyAfter(s string, chars string, ix int) int// in "github.com/synesissoftware/ANGoLS/strings"
// Slices a string into all substings after each instance of the byte sep
// and returns a slice of those substrings.
//
// If s does not contain sep, SplitAfterByte returns a slice of length 1
// whose only element is s.
//
// It is equivalent to [SplitAfterByteN] with a count of -1.
func SplitAfterByte(s string, sep byte) []string
// Slices s into substrings after each instance of the byte sep and returns
// a slice of those substrings.
//
// ix determines the number of substrings to return:
// - n > 0: at most n substrings; the last substring being the unsplit
// remainder;
// - n == 0: the result is nil (zero substrings);
// - n < 0: all substrings.
func SplitAfterByteN(s string, sep byte, ix int) []string
// Slices a string into all substings after each instance of the rune sep
// and returns a slice of those substrings.
//
// If s does not contain sep, SplitAfterRune returns a slice of length 1
// whose only element is s.
//
// It is equivalent to [SplitAfterRuneN] with a count of -1.
func SplitAfterRune(s string, sep rune) []string
// Slices s into substrings after each instance of the rune sep and returns
// a slice of those substrings.
//
// ix determines the number of substrings to return:
// - n > 0: at most n substrings; the last substring being the unsplit
// remainder;
// - n == 0: the result is nil (zero substrings);
// - n < 0: all substrings.
func SplitAfterRuneN(s string, sep rune, ix int) []string
// Slices a string into all substings after each instance of any of the
// runes in chars and returns a slice of those substrings.
//
// If s does not contain any of the runes in chars and chars is not empty,
// SplitAfterAny returns a slice of length 1 whose only element is s.
//
// It is equivalent to [SplitAfterAnyN] with a count of -1.
func SplitAfterAny(s, chars string) []string
// Slices s into substrings after each instance of any of the runes in chars
// and returns a slice of those substrings.
//
// ix determines the number of substrings to return:
// - n > 0: at most n substrings; the last substring being the unsplit
// remainder;
// - n == 0: the result is nil (zero substrings);
// - n < 0: all substrings.
func SplitAfterAnyN(s, chars string, ix int) []string
// Slices a string into all substings after each instance of any of the
// bytes in seps and returns a slice of those substrings.
//
// If s does not contain any of the bytes in seps and seps is not empty,
// SplitAfterAnyBytes returns a slice of length 1 whose only element is s.
//
// It is equivalent to [SplitAfterAnyBytesN] with a count of -1.
func SplitAfterAnyBytes(s string, seps []byte) []string
// Slices a string into all substings after each instance of any of the
// bytes in seps and returns a slice of those substrings.
//
// ix determines the number of substrings to return:
// - n > 0: at most n substrings; the last substring being the unsplit
// remainder;
// - n == 0: the result is nil (zero substrings);
// - n < 0: all substrings.
func SplitAfterAnyBytesN(s string, seps []byte, ix int) []string
// Slices a string into all substings after each instance of any of the
// runes in seps and returns a slice of those substrings.
//
// If s does not contain any of the runes in seps and seps is not empty,
// SplitAfterAnyRunes returns a slice of length 1 whose only element is s.
//
// It is equivalent to [SplitAfterAnyN] with a count of -1.
func SplitAfterAnyRunes(s string, seps []rune) []string
// Slices a string into all substings after each instance of any of the
// runes in seps and returns a slice of those substrings.
//
// ix determines the number of substrings to return:
// - n > 0: at most n substrings; the last substring being the unsplit
// remainder;
// - n == 0: the result is nil (zero substrings);
// - n < 0: all substrings.
func SplitAfterAnyRunesN(s string, seps []rune, ix int) []string// in "github.com/synesissoftware/ANGoLS/strings"
// Takes a single string and returns a chomped version of it, where chomping
// removes a single trailing '\n' character, a single trailing '\r'
// character, or a single trailing sequence of "\r\n".
func StringChomp(s string) string
// Takes a single string and returns a fully/repeatedly chomped version of,
// where full/repeated chomping removes all trailing '\r' and/or '\n'
// characters.
func StringChompAll(s string) stringExamples are provided in the examples directory, along with a markdown description for each. A detailed list TOC of them is provided in EXAMPLES.md.
Defect reports, feature requests, and pull requests are welcome on https://github.com/synesissoftware/ANGoLS.
T.B.C.
ANGoLS is released under the 3-clause BSD license. See LICENSE for details.