/funcional

Use functions to manipulate your data more easily.

Primary LanguageGoOtherNOASSERTION

funcional

Go Reference

A very useful library to manipulate data structures in Go, let's try it Gophers. funcional uses generics, released in Go 1.18, for easy reading.

Check the testing

go test -coverprofile cover.out
go tool cover -func cover.out

Install

go get -u github.com/valerianomacuri/funcional

Examples

Filter

filteredValues := Filter([]int{1, 2, 3, 4}, func(num int) bool {
		if num == 1 {
			return false
		} else {
			return true
		}
	})

Find

slice := []int{1, 2, 3, 4}
foundValue, ok := Find(slice, func(value int) bool {
	return value == 5
})

Includes

slice := []int{1, 3, 4, 5}
isIncluded := Includes(slice, 1)

Map

result := Map([]int{1, 2, 3, 4, 5}, func(value int) int {
            return value + 1
        })

Reduce

slice := []int{1, 2, 3, 4, 5}
reducedValue := Reduce(slice, 0, func(num1, num2 int) int {
    return num1 + num2
})

Some

slice := []int{1, 3, 4, 5}
result := Some(slice, func(value int) bool {
    return (value % 2) == 0
})