golodash

package module
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2024 License: MIT Imports: 0 Imported by: 0

README

go-lodash

A set of lodash-like utilities in Golang.

Installation

$ go get github.com/189/golodash

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Every added in v0.1.6

func Every[T ~[]E, E comparable](items T, fn Predicate[E]) bool

Return true only if all Predicate(item) == true

func Filter

func Filter[T ~[]E, E comparable](items T, fn Predicate[E]) T

Filter the slice object

func ForEach added in v0.1.6

func ForEach[T ~[]E, E any](items T, callback func(idx int, item E) bool)

Another forms for for loop instead of for .. range, loop will stop when callback with False result

func GetKeys

func GetKeys[K comparable, V any](obj map[K]V) []K

Retrive all the keys from a map

func GetValues

func GetValues[K comparable, V any](obj map[K]V) []V

Retrive all the values from a map

func Map

func Map[T any, U any](items []T, mapper func(T) U) []U

Iterate over each item in a slice sequentially

Example
nums := []int32{1, 2, 3, 4, 5}
ret := Map(nums, func(item int32) int32 {
	return item * 2
})

fmt.Printf("%v", ret)
Output:

{2,4,6,8,10}

func Reduce

func Reduce[T any, U any](items []T, initial U, reducer func(U, T) U) U

Iterate over each item in the slice sequentially, passing the result of the previous iteration to the next iteration's function execution

Example
nums := []int32{1, 2, 3, 4, 5}
total := Reduce(nums, 0, func(prev int32, now int32) int32 {
	return prev + now
})
fmt.Printf("%v", total)
Output:

16

func Some added in v0.1.6

func Some[T ~[]E, E comparable](items T, fn Predicate[E]) bool

Return true if any Predicate(item) == true

Types

type Predicate added in v0.1.6

type Predicate[T comparable] func(T) bool

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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