Skip to content

micotom/gfuncs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GFuncs

Implementation of slice functions for Go 1.18+ inspired by the Kotlin Collection extensions.

Download

go get github.com/micotom/gfuncs

(Some of the) Supported Functions

Fold : []T, V, (V, T -> V) -> V

func Fold[T any, V any](slice []T, initial V, fn func(acc V, t T) V) V

FoldIndexed : []T, V, (int, T, V -> V) -> V

func FoldIndexed[T any, V any](slice []T, initial V, fn func(index int, acc V, t T) V) V

SortBy : []T, (T -> V) -> []T

func SortBy[T any, V constraints.Ordered](slice []T, fn func(t T) V) []T

Filter : []T, (T -> bool) -> []T

func Filter[T any](slice []T, fn func(t T) bool) []T

FilterIndexed : []T, (int, T -> bool) -> []T

func FilterIndexed[T any](slice []T, fn func(i int, t T) bool) []T

GroupBy : []T, (T -> V) -> map[V][]T

func GroupBy[T any, V comparable](slice []T, fn func(t T) V) map[V][]T

SumBy : []T, (T -> V) -> *V, error

func SumBy[T any, V Number](slice []T, fn func(t T) V) (*V, error)

Map : []T, (T -> V) -> []V

func Map[T any, V any](slice []T, fn func(t T) V) []V

MapIndexed : []T, (int, T -> V) -> []V

func MapIndexed[T any, V any](slice []T, fn func(i int, t T) V) []V 

Flatten : [][]T -> []T

func Flatten[T any](slice [][]T) []T

Zip : []T, []V -> []Tuple[T, V]

func Zip[T any, V any](sliceT []T, sliceV []V) []Tuple[T, V]

Find : []T, (T -> bool) -> *T

func Find[T any](slice []T, fn func(t T) bool) *T

Any : []T, (T -> bool) -> bool

func Any[T any](slice []T, fn func(t T) bool) bool

All : []T, (T -> bool) -> bool

func All[T any](slice []T, fn func(t T) bool) bool

About

Slice helper functions

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages