gogeneric

package
v0.0.0-...-404d2c9 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddInt

func AddInt(a, b int) int

AddInt return the sum of two integers

func AddNum

func AddNum[T Number](a, b T) T

AddNum return the sum of two numbers

func AllMatch

func AllMatch[T any](datas []T, f func(T) bool) bool

AllMatch check all elements matching the given function

func AnyMatch

func AnyMatch[T any](datas []T, f func(T) bool) bool

AnyMatch check any element matching the given function

func Filter

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

Filter returns elements matching the filter function

func ForEach

func ForEach[T any](datas []T, f func(T))

ForEach process each element by calling f

func Map

func Map[T any](datas []T, f func(T) T) []T

Map processes and group elements by function f

func Reduce

func Reduce[T any](datas []T, result []T, f func(T, []T) []T) []T

Reduce process elements by func f and return

func SliceMax

func SliceMax[T cmp.Ordered](s []T) T

SliceMax return the maximum element of slice

func SumFloats

func SumFloats(m map[string]float64) float64

SumFloats return the sum of map values

func SumInts

func SumInts(m map[string]int64) int64

SumInts return the sum of map values

func SumNumber

func SumNumber[K comparable, V Number](m map[string]V) V

SumNumber returns the sum of map values

Types

type GenericQueue

type GenericQueue[T any] struct {
	// contains filtered or unexported fields
}

GenericQueue queue implemented by the generic

func NewGenericQueue

func NewGenericQueue[T any](capacity int) *GenericQueue[T]

NewGenericQueue creates a new GenericQueue instance

func (*GenericQueue[T]) Peek

func (q *GenericQueue[T]) Peek() (_ T)

Peek get the front element of the GenericQueue

func (*GenericQueue[T]) Pop

func (q *GenericQueue[T]) Pop() (_ T)

Pop remove front element of the GenericQueue

func (*GenericQueue[T]) Push

func (q *GenericQueue[T]) Push(v T)

Push insert element into the GenericQueue

func (*GenericQueue[T]) Size

func (q *GenericQueue[T]) Size() int

Size returns the size of the GenericQueue

type Number

type Number interface {
	int | int32 | int64 | float32 | float64
}

Number stands for numberic type

Jump to

Keyboard shortcuts

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