generics

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All[T any](vs []T, fn func(T) bool) bool

Run predicate `fn` on all elems of `vs` and return true if all elems of `vs` match the predicate.

func Any

func Any[T any](vs []T, fn func(T) bool) bool

Run predicate `fn` on all elems of `vs` and return true if any elems of `vs` match the predicate.

func CoerceInt

func CoerceInt[N Numeric](val N) any

Coerce a numeric to an integer value of appropriate signage and size.

func HasFraction

func HasFraction(num float64) bool

Does the given float have a faction?

func MapList

func MapList[T any](lst []T, fn func(T) bool) []T

Map a function on all elements of a list returning a new list containing all the values from the initial list for which the function returns `true`.

func MapMap

func MapMap[K comparable, V any](m map[K]V, fn func(K, V) bool) map[K]V

Apply a function on all key/value pairs in a map and return a new map of key/value pairs containing all elements for which the provided function returns `true`.

func Member

func Member[T constraints.Ordered](ordered []T, elt T) bool

Returns true if the container specified by `ordered` contains the member specified by `elt`.

func Number

func Number[V Numeric](val V) any

If the given thing does not have a fraction, convert it to an int.

func ValueOf

func ValueOf(thing any) any

Attempt to ascertain the numeric value (if any) for a given thing.

If the type of `thing` is a floating-point number, then the value will be converted via `Number` to either an explicit float or to an integer type if there is no fraction.

If the type of `thing` is any other type, then it will be returned with no conversion.

Types

type Numeric

type Numeric interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
		~float32 | ~float64
}

Generic "numeric" type constraint.

Jump to

Keyboard shortcuts

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