generic

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2023 License: MIT Imports: 2 Imported by: 5

README

generic

import "github.com/pandodao/generic"

Package generic contains generic functions that can be used by any other package.

Index

func Must

func Must[T any](v T, err error) T

Must panics if err is not nil, otherwise returns v.

func Ptr

func Ptr[T any](v T) *T

Ptr returns a pointer to v.

func Try

func Try[T any](v T, err error) T

Try returns v regardless of err.

Generated by gomarkdoc

Documentation

Overview

Package generic contains generic functions that can be used by any other package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainSlice added in v1.0.3

func ContainSlice[T comparable](s []T, v T) bool

func CopySlice added in v1.0.2

func CopySlice[T any](s []T) []T

func HashSlice added in v1.0.2

func HashSlice[K comparable, T any](s []T, fn func(T) K) map[K]T

func IndexSlice added in v1.0.3

func IndexSlice[T comparable](s []T, v T) int

func MapKeys added in v1.0.2

func MapKeys[K comparable, V any](m map[K]V) []K

func MapSlice added in v1.0.2

func MapSlice[T, V any](s []T, fn func(T) V) []V

func Must

func Must[T any](v T, err error) T

Must panics if err is not nil, otherwise returns v.

func Ptr

func Ptr[T any](v T) *T

Ptr returns a pointer to v.

func Reverse added in v1.0.1

func Reverse[T any](s []T)

Reverse reverses the elements of s.

func SortMapKeys added in v1.0.2

func SortMapKeys[K cmp.Ordered, V any](m map[K]V) []K

func Try

func Try[T any](v T, err error) T

Try returns v regardless of err.

Types

This section is empty.

Jump to

Keyboard shortcuts

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