functools

package module
v0.0.0-...-aae8e6e Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2024 License: MIT Imports: 0 Imported by: 4

README

Function Tools

Map

example:

	a = Map(func(i int) int {
		return i + 1
	}, a)

Filter

example:

	a = Filter(func(i int) bool {
		return i < 50
	}, a)

Reduce

example:

	n := Reduce(func(x, y int) int {
		return x + y
	}, a, 0)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filter

func Filter[A any](f FilterFunc[A], list []A) []A

func Map

func Map[A any, B any](f MapFunc[A, B], list []A) []B

func Max

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

func Min

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

func Range

func Range[T Int | Uint](start, stop, step T) []T

func Reduce

func Reduce[A any](f ReduceFunc[A], list []A, init A) A

func Reverse

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

func Sum

func Sum[T Number](slice []T) T

Types

type FilterFunc

type FilterFunc[A any] func(A) bool

type Float

type Float interface {
	~float32 | ~float64
}

type Int

type Int interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type MapFunc

type MapFunc[A any, B any] func(A) B

type Number

type Number interface {
	Int | Uint | Float
}

type ReduceFunc

type ReduceFunc[A any] func(A, A) A

type Tuple

type Tuple[A any, B any] struct {
	V1 A
	V2 B
}

func NewTuple

func NewTuple[A any, B any](a A, b B) Tuple[A, B]

func Zip

func Zip[A any, B any](a []A, b []B) []Tuple[A, B]

func (Tuple[A, B]) Values

func (tuple Tuple[A, B]) Values() (A, B)

type Uint

type Uint interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}

Jump to

Keyboard shortcuts

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