Documentation ¶
Index ¶
- Constants
- func All[T any](slice []T, predicate func(T) bool) bool
- func Filter[T any](slice []T, predicate func(T) bool) []T
- func GroupString(s string) []string
- func KeyValuePairs(input string) map[string]string
- func LinesByParagraph(lines []string) [][]string
- func LowestTrue(lowFalseStart int, pred func(int) (bool, error)) (int, error)
- func Map[T, U any](slice []T, mapper func(T) U) []U
- func MapE[T, U any](slice []T, mapper func(T) (U, error)) ([]U, error)
- func MapSum[T Number](slicesOfItems [][]T) []T
- func MappedSum[T any, U constraints.Integer | constraints.Float | ~string](slice []T, mapper func(T) U) U
- func Max[T Number](items []T) T
- func MustParseInts(commaString string, separator string) []int
- func MustReadFileInts(filename string) []int
- func MustReadFileString(filename string) string
- func MustReadLines(filename string) []string
- func MustReadSingleInt(filename string) int
- func MustStringsToInts(strings []string) []int
- func ParseFieldInts(s string) ([]int, error)
- func ParseGrid(lines []string) ([][]int, error)
- func ParseInts(commaString string, separator string) ([]int, error)
- func ParseLinesOfInts(commaStrings []string, separator string) ([][]int, error)
- func ParseRegexInts(inputs []string, allowNegative bool) [][]int
- func ReadFile(filename string) ([]byte, error)
- func ReadFileInts(filename string) ([]int, error)
- func ReadFileString(filename string) (string, error)
- func ReadLines(filename string) ([]string, error)
- func RemoveBlanks(ss []string) []string
- func Reverse(s string) string
- func Split2[T any](slice []T, predicate func(T) bool) ([]T, []T)
- func SplitAfter[T any](slice []T, predicate func(T) bool) [][]T
- func SplitBefore[T any](slice []T, predicate func(T) bool) [][]T
- func StringsToInt32s(strings []string) ([]int32, error)
- func StringsToInts(strings []string) ([]int, error)
- func Sum[T Number](items []T) T
- func SurroundingNewlineTrimmedLines(s string) []string
- func Transpose(input [][]int) [][]int
- func TrimmedLines(s string) []string
- type Number
- type StringsAndInts
Constants ¶
const MaxInt = int(MaxUint >> 1)
const MaxUint = ^uint(0)
Variables ¶
This section is empty.
Functions ¶
func GroupString ¶
GroupString returns the input string, broken into runs of consecutive characters
func KeyValuePairs ¶
KeyValuePairs splits a space-separated sequence of colon-separated key:value pairs into a map.
func LinesByParagraph ¶
LinesByParagraph takes a slice of strings, and returns a slice of slices of strings: it separates paragraphs (multiple newlines).
func MapSum ¶
func MapSum[T Number](slicesOfItems [][]T) []T
MapSum returns a slice of the Sums of sublists.
func MappedSum ¶
func MappedSum[T any, U constraints.Integer | constraints.Float | ~string](slice []T, mapper func(T) U) U
MappedSum runs `mapper` on each element, and sums the result.
func MustParseInts ¶
MustParseInts parses a string of separated ints into a slice of ints, or panics.
func MustReadFileInts ¶
MustReadFileInts reads a file of ints, one per line, or panics.
func MustReadFileString ¶
MustReadFileString reads a string from a file or panics.
func MustReadLines ¶
MustReadLines reads a file and returns a slice of strings, one per line, or dies. MustReadFileString reads a string from a file or panics.
func MustReadSingleInt ¶
MustReadSingleInt reads a single integer from a file.
func MustStringsToInts ¶
MustStringsToInts takes a slice of strings and returns a slice of ints, or panics.
func ParseFieldInts ¶
ParseFieldInts parses a string of ints separated by runs of whitespace into a slice of ints.
func ParseLinesOfInts ¶
ParseLinesOfInts runs ParseInts on every string in the passed slice, passing back a slice of slices of ints.
func ParseRegexInts ¶
ParseRegexInts takes a slice of lines of text. For each line, it searches for integers using a regex, and turns each into an integer. `allowNegative` determines whether a preceding minus sign is included in the regex or not.
func ReadFileInts ¶
ReadFileInts reads a file of ints, one per line
func ReadFileString ¶
ReadFileString reads a file and returns it as a string, trimmed.
func RemoveBlanks ¶
RemoveBlanks returns a slice of strings, but trimmed, and with empty/all-whitespace strings removed.
func Split2 ¶
Split2 is a simple filter over a slice. It returns two slices: the first holding elements for which the predicate returned true, the second those for which it returned false.
func SplitAfter ¶
SplitAfter takes a slice and a predicate, and returns the slice chunked, split after any element where the predicate returns true.
func SplitBefore ¶
SplitBefore takes a slice and a predicate, and returns the slice chunked, split before any element where the predicate returns true.
func StringsToInt32s ¶
StringsToInt32s takes a slice of strings and returns a slice of int32s
func StringsToInts ¶
StringsToInts takes a slice of strings and returns a slice of ints
func SurroundingNewlineTrimmedLines ¶
SurroundingNewlineTrimmedLines trimes leading and trailing newlines from the input, then splits on newlines.
func TrimmedLines ¶
TrimmedLines takes a string, splits it into lines, and trims each line of starting and ending whitespace.
Types ¶
type Number ¶
type Number interface { constraints.Float | constraints.Integer }
Number is a Float or Integer
type StringsAndInts ¶
type StringsAndInts struct { Strings []string Ints []int Input string // the original input, when appropriate }
StringsAndInts is a set of parsed strings and ints from a line of input.
func ParseByRegexps ¶
func ParseByRegexps(inputs []string, regexps []*regexp.Regexp) ([]StringsAndInts, error)
ParseByRegexps applies the given list of regexps (in order) to each line of the input. When one matches, the groups in it are parsed into integers if possible, strings otherwise.
func ParseStringsAndInts ¶
func ParseStringsAndInts(lines []string, fields int, stringFields []int, intFields []int) ([]StringsAndInts, error)
ParseStringsAndInts takes a slice of input lines, a slice of string field indexes, and a slice of int field indexes. It returns a slice of StringsAndInts structs, one per line.