kittehs

package
v0.10.12 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Taken from https://github.com/egtann/strip-wildcard-prefix/blob/main/strip_wildcard.go. See discussion in https://github.com/golang/go/issues/64909.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All(xs ...bool) bool

func ContainedIn

func ContainedIn[T comparable](xs ...T) func(T) bool

func DecodeURLData added in v0.5.0

func DecodeURLData[T any](data string, dst T) error

func EncodeURLData added in v0.5.0

func EncodeURLData(data any) (string, error)

func FSToMap added in v0.2.0

func FSToMap(in fs.FS) (map[string][]byte, error)

func Filter

func Filter[T any](ts []T, f func(T) bool) []T

func FilterMapKeys

func FilterMapKeys[K comparable, V any](m map[K]V, f func(K) bool) map[K]V

func FilterNils

func FilterNils[T any](ts []*T) []*T

func FilterZeroes added in v0.3.0

func FilterZeroes[T comparable](ts []T) []T

func FindFirst

func FindFirst[T any](vs []T, f func(T) bool) (int, T)

func FirstNonZero added in v0.9.2

func FirstNonZero[T comparable](opts ...T) (t T)

FirstNonZero returns first opt which is non-zero. If opts is empty, the zero value of T is returned.

func HashString32

func HashString32(s string) uint32

HashString32 computes the 32-bit FNV-1a hash of s in software. maphash.String does only 64bit version. (in Alan I trust: https://github.com/google/starlark-go/blob/f86470692795f8abcf9f837a3c53cf031c5a3d7e/starlark/hashtable.go#L435)

func HashString64

func HashString64(s string) uint64

func IsNil

func IsNil[T any](x *T) bool

func IsNotNil

func IsNotNil[T any](x *T) bool

func IsNotZero added in v0.3.0

func IsNotZero[T comparable](t T) bool

func IsZero added in v0.3.0

func IsZero[T comparable](t T) bool

func LazyCache added in v0.10.10

func LazyCache[T, P any](f func(P) T, p P) func() T

LazyCache wraps a function and a single input. The first call to the wrapper calls the wrapped function. Subsequent calls return the first result.

func ListToMap

func ListToMap[T any, K comparable, V any](ts []T, f func(T) (K, V)) map[K]V

This does not guard against duplicate keys.

func ListToMapError

func ListToMapError[T any, K comparable, V any](ts []T, f func(T) (K, V, error)) (map[K]V, error)

func MapToMemFS added in v0.2.0

func MapToMemFS(in map[string][]byte) (fs.FS, error)

func MarshalProtoMapJSON added in v0.6.0

func MarshalProtoMapJSON[K comparable, V proto.Message](xs map[K]V) ([]byte, error)

func MarshalProtoSliceJSON added in v0.6.0

func MarshalProtoSliceJSON[T proto.Message](xs []T) ([]byte, error)

func MatchLongestSuffix

func MatchLongestSuffix(s string, suffixes []string) string

func Must0

func Must0(err error)

func Must1

func Must1[A any](a A, err error) A

func Must11

func Must11[A, X any](f func(A) (X, error)) func(A) X

Lazy Must1 with 1 input argument.

func Must12

func Must12[A, X, Y any](f func(A) (X, Y, error)) func(A) (X, Y)

Lazy Must2 with 1 input argument.

func Must2

func Must2[A, B any](a A, b B, err error) (A, B)

func MustEqual

func MustEqual[T comparable](a, b T, msg ...any)

func NewFilter

func NewFilter[T any](f func(T) bool) func([]T) []T

func NewMapFilter

func NewMapFilter[K comparable, V any](f func(K, V) bool) func(map[K]V) map[K]V

func NewMapKeysFilter

func NewMapKeysFilter[K comparable, V any](f func(K) bool) func(map[K]V) map[K]V

func NormalizeURL added in v0.4.0

func NormalizeURL(rawURL string, secure bool) (string, error)

NormalizeURL ensures that the given URL has the right scheme prefix, and no suffix (e.g. path) after the host address.

func Panic

func Panic(msg any)

func SetPanicFunc

func SetPanicFunc(f func(any))

func Should1

func Should1[T any](alt T) func(t T, err error) T

If err is nil, return t. Else return alt.

func Should11

func Should11[X, Y any](alt Y, f func(X) (Y, error)) func(X) Y

func ShouldFunc1

func ShouldFunc1[T any](alt func(error) T) func(t T, err error) T

func ShouldFunc11

func ShouldFunc11[X, Y any](alt func(error) Y, f func(X) (Y, error)) func(X) Y

Same as Should1s, but alt is lazy.

func StripWildcardPrefix added in v0.4.4

func StripWildcardPrefix(prefix string, h http.Handler) http.Handler

func ToString

func ToString[T any](t T) string

func Transform

func Transform[A, B any](as []A, f func(A) B) []B

func TransformError

func TransformError[A, B any](as []A, f func(A) (B, error)) ([]B, error)

func TransformFilter added in v0.6.0

func TransformFilter[A, B any](as []A, f func(A) *B) []B

func TransformMap

func TransformMap[A0, A1 comparable, B0, B1 any](m map[A0]B0, f func(A0, B0) (A1, B1)) map[A1]B1

func TransformMapError

func TransformMapError[A0, A1 comparable, B0, B1 any](m map[A0]B0, f func(A0, B0) (A1, B1, error)) (map[A1]B1, error)

func TransformMapToList

func TransformMapToList[K comparable, V, T any](m map[K]V, f func(K, V) T) []T

func TransformMapToListError

func TransformMapToListError[K comparable, V, T any](m map[K]V, f func(K, V) (T, error)) ([]T, error)

func TransformMapValues

func TransformMapValues[A comparable, B0, B1 any](m map[A]B0, f func(B0) B1) map[A]B1

func TransformMapValuesError

func TransformMapValuesError[A comparable, B0, B1 any](m map[A]B0, f func(B0) (B1, error)) (map[A]B1, error)

func TransformToStrings

func TransformToStrings[T any](ts []T) []string

func TransformWithIndex

func TransformWithIndex[A, B any](as []A, f func(int, A) B) []B

func TxtarToFS added in v0.2.0

func TxtarToFS(a *txtar.Archive) (fs.FS, error)

func ValidateList

func ValidateList[T any](vs []T, f func(int, T) error) (int, error)

Returns first index with error.

Types

type DoNotCompare added in v0.3.0

type DoNotCompare [0]func()

type DoNotCopy added in v0.3.0

type DoNotCopy [0]sync.Mutex

type FilterFS added in v0.7.1

type FilterFS struct {
	fs.FS // embed underlying FS

	Pred func(fs.DirEntry) bool // DirEntry predicate
}

FilterFS will filter entries based on a predicate function.

func NewFilterFS added in v0.7.1

func NewFilterFS(fsys fs.FS, pred func(fs.DirEntry) bool) (*FilterFS, error)

NewFilterFS returns a new FilterFS wrapping the given FS and predicate. `nil` pred assumes to always return true.

func (*FilterFS) ReadDir added in v0.7.1

func (f *FilterFS) ReadDir(name string) ([]fs.DirEntry, error)

ReadDir implements fs.ReadDirFS.

type IndentedStringWriter added in v0.8.5

type IndentedStringWriter struct {
	DoNotCopy
	DoNotCompare

	W      io.Writer
	Indent string
	// contains filtered or unexported fields
}

func NewIndentedStringWriter added in v0.8.5

func NewIndentedStringWriter(w io.Writer, indent string) *IndentedStringWriter

func (*IndentedStringWriter) Write added in v0.8.5

func (w *IndentedStringWriter) Write(p []byte) (n int, err error)

type String

type String string

This is silly, but string does not implement fmt.Stringer for some reaosn.

func (String) String

func (s String) String() string

Jump to

Keyboard shortcuts

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