fun

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2023 License: Apache-2.0 Imports: 0 Imported by: 1

Documentation

Overview

Putting the FUN in FUNctions!

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Each

func Each[T any](list []T, apply func(x T))

Apply a func to each item in a slice

func Filter

func Filter[T any](list []T, filter func(v T) bool) []T

returns a new list that is a subset of the previous list with elements that evaluate true for the given filter function.

func FirstOrElse

func FirstOrElse[T any](list []T, other T) T

Retrieve the first element from the list or the provided `other`

func Map

func Map[T any, Y any](list []T, apply func(i int, x T) Y) []Y

execute a func over all elements in list, returning a new list with the results

func Reduce

func Reduce[T any, V any](list []T, initial V, reducer func(v T, accumulator V) V) V

Reduce takes a list(slice) and produces a single value. The [initial] parameter will be what is passed to to the first iteration of the [reducer] fun.

func ReduceI

func ReduceI[T any, V any](list []T, initial V, reducer func(i int, v T, accumulator V) V) V

Same as Reduce, but also passes the loop iterator

func ToMap

func ToMap[K comparable, V any](list []V, fn func(idx int, v V) (K, V)) map[K]V

convert a slice to a map, the provided function will return the key and value to populate the map with

func Values

func Values[K comparable, T any](m map[K]T) []T

Types

type Tuple

type Tuple[T any, V any] struct {
	E1 T
	E2 V
}

func Zip

func Zip[T any, V any](slice1 []T, slice2 []V) []Tuple[T, V]

Jump to

Keyboard shortcuts

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