Skip to content

Lleuad/gotools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

functools

A collection of functional looking functions I kept rewriting in my Go projects.

Error Handling

PassErr

func PassErr[T any](t T, err error) T

Ignores err and returns t.

LogErr

func LogErr[T any](t T, err error) T

Logs err with log.Println if err is non-nil and returns t.

FatalErr

func FatalErr[T any](t T, err error) T

Logs err with log.Fatalln if err is non-nil, otherwise returns t.

PanicErr

func FatalErr[T any](t T, err error) T

Logs err with log.Panicln if err is non-nil, otherwise returns t.

Reduce

func Reduce[T any](f func(T, T) T, a []T) T

Applies f cumulatively to the items in a, left to right. Similarly to Haskell's foldl'

Map

Map

func Map[T any, V any](f func(T) V, a []T) []V

Maps f over the items in a one by one.

MaptoStr

func MaptoStr[T any](a []T) []string

Equivalent to Map(fmt.Sprintf, a)

Filter

Filter

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

Returns a slice of all items v in a for which f(v) returns true

Find

func Find[T any](f func(T) bool, a []T) (int, T)

Returns first index and item v in a for which f(v) returns true

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages