generic

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2025 License: MIT Imports: 0 Imported by: 2

README

Go-Generic-Basic

This is a simple example of using generics in Go.

Dependencies

API Documentation

Please see the API Documentation for api documentation.

To generate the API documentation, run the following command:

gomarkdoc -o docs/api.md ./...

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Authors

Documentation

Overview

Package generic implements the functions, types, and interfaces for the module.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Choose added in v0.2.6

func Choose[T any](cond bool, l, r T) T

Choose returns the left value if cond is true, otherwise it returns the right value. This function is useful when you need to conditionally choose between two values.

func ChooseFunc added in v0.3.0

func ChooseFunc[T any](cond bool, l, r func() T) T

ChooseFunc returns the result of the left function if cond is true, otherwise it returns the result of the right function. This function is useful when you need to conditionally choose between two functions.

func ChooseLeft added in v0.1.6

func ChooseLeft[L, R any](l L, _ R) L

ChooseLeft returns the leftmost value, ignoring the right value. This function is useful when you need to prioritize the left value over the right.

func ChooseRight added in v0.1.6

func ChooseRight[L, R any](_ L, r R) R

ChooseRight returns the rightmost value, ignoring the left value. This function is useful when you need to prioritize the right value over the left.

func Must

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

Must is a utility function that ensures a value is not nil and returns it. If the error is not nil, it panics with the error message.

func Must2

func Must2[T any, U any](v T, u U, err error) (T, U)

Must2 is a utility function that ensures a value is not nil and returns it.

func MustLookup

func MustLookup[T any](v T, ok bool) T

MustLookup is a utility function that ensures a value is not nil and returns it. If the error is not nil, it panics with the error message.

func MustLookupOr

func MustLookupOr[T any](def T, v T, ok bool) T

MustLookupOr is a utility function that ensures a value is not nil and returns it. If the error is not nil, it returns the default value.

func MustLookupOrNil

func MustLookupOrNil[T any](v *T, ok bool) *T

MustLookupOrNil is a utility function that ensures a value is not nil and returns it. If the error is not nil, it returns nil.

func MustLookupOrZero

func MustLookupOrZero[T any](v T, ok bool) T

MustLookupOrZero is a utility function that ensures a value is not nil and returns it. If the error is not nil, it returns a zero value.

func MustOr

func MustOr[T any](def T, v T, err error) T

MustOr is a utility function that ensures a value is not nil and returns it. If the error is not nil, it returns the default value.

func MustOrNil

func MustOrNil[T any](v *T, err error) *T

MustOrNil is a utility function that ensures a value is not nil and returns it. If the error is not nil, it returns nil.

func MustOrZero

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

MustOrZero is a utility function that ensures a value is not nil and returns it. If the error is not nil, it returns a zero value.

func OnlyLeft added in v0.1.6

func OnlyLeft[L, R1, R2 any](l L, _ R1, _ R2) L

OnlyLeft returns the leftmost value, ignoring all other values. This function is useful when you need to extract the leftmost value from a tuple.

func OnlyMiddle added in v0.1.6

func OnlyMiddle[L, M, R any](_ L, m M, _ R) M

OnlyMiddle returns the middle value, ignoring all other values. This function is useful when you need to extract the middle value from a tuple.

func OnlyRight added in v0.1.6

func OnlyRight[L1, L2, R any](_ L1, _ L2, r R) R

OnlyRight returns the rightmost value, ignoring all other values. This function is useful when you need to extract the rightmost value from a tuple.

func OrNil

func OrNil[T any](_ T, err error) error

OrNil is a utility function that ensures a value is not nil and returns it.

func OrNil2

func OrNil2[T any](_, _ T, err error) error

OrNil2 is a utility function that ensures a value is not nil and returns it.

Types

This section is empty.

Directories

Path Synopsis
Package cmp implements the functions, types, and interfaces for the module.
Package cmp implements the functions, types, and interfaces for the module.
Package maps implements the functions, types, and interfaces for the module.
Package maps implements the functions, types, and interfaces for the module.
Package result implements the unified result type for operations
Package result implements the unified result type for operations
Package settings provides type-safe configuration management with default value handling.
Package settings provides type-safe configuration management with default value handling.
Package slices implements the functions, types, and interfaces for the module.
Package slices implements the functions, types, and interfaces for the module.
Package strings implements the functions, types, and interfaces for the module.
Package strings implements the functions, types, and interfaces for the module.
Package trans implements the functions, types, and interfaces for the module.
Package trans implements the functions, types, and interfaces for the module.
reflection
Package reflection implements the functions, types, and interfaces for the module.
Package reflection implements the functions, types, and interfaces for the module.
Package types implements the functions, types, and interfaces for the module.
Package types implements the functions, types, and interfaces for the module.

Jump to

Keyboard shortcuts

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