go-funk

A modern Go utility library which provides helpers (map, find, contains, filter, …)

go-funk is a modern Go library based on reflect.

Generic helpers rely on reflect, be careful this code runs exclusively on runtime so you must have a good test suite.

These helpers have started as an experiment to learn reflect. It may looks like lodash in some aspects but it will have its own roadmap, lodash is an awesome library with a lot of works behind it, all features included in go-funk come from internal use cases.

You can also find typesafe implementation in the godoc.

funk.Find

Finds an element in a slice based on a predicate.

r := funk.Find([]int{1, 2, 3, 4}, func(x int) bool {
    return x%2 == 0
}) // 2
Publikováno v Go