1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-13 01:02:28 +08:00

Slice: find v2 (#17)

* If slice len is zero then return false
* Convert find to generic form.
* If return T is nil then no items matched the predicate func
This commit is contained in:
donutloop
2022-01-07 13:19:27 +01:00
committed by GitHub
parent 3e9a2b5c59
commit 30d798366b
4 changed files with 14 additions and 19 deletions

View File

@@ -401,7 +401,7 @@ func Drop(slice interface{}, n int) interface{} //creates a slice with `n` eleme
func Every(slice, function interface{}) bool //return true if all of the values in the slice pass the predicate function, function signature should be func(index int, value interface{}) bool
func None(slice, function interface{}) bool // return true if all the values in the slice mismatch the criteria
func Filter [T any] (slice []T, fn func(index int, t T) bool) []T //filter slice, fn signature should be func(int, T) bool.
func Find(slice, function interface{}) (interface{}, bool) //iterates over elements of slice, returning the first one that passes a truth test on function.function signature should be func(index int, value interface{}) bool .
func Find[T any](slice []T, fn func(index int, t T) bool) (*T, bool) //iterates over elements of slice, returning the first one that passes a truth test on function.function signature should be func(index int, value interface{}) bool .
func FlattenDeep(slice interface{}) interface{} //flattens slice recursive
func ForEach [T any] (slice []T, fn func(index int, t T)) //iterates over elements of slice and invokes function for each element, fn signature should be func(int, T ).
func IntSlice(slice interface{}) ([]int, error) //convert value to int slice