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

Slice: find nothing case (#11)

The current behavior can result into wired edge cases.

**Current behavior**

if find was unsuccessfully then it will return the first element of the
slice

**Desired behavior**

if find was unsuccessfully then it should return negative ok and a none
value
This commit is contained in:
donutloop
2022-01-02 15:05:27 +01:00
committed by GitHub
parent b4a49fccfd
commit f15131f032
4 changed files with 27 additions and 6 deletions

View File

@@ -395,7 +395,7 @@ func DeleteByIndex(slice interface{}, start int, end ...int) (interface{}, error
func Drop(slice interface{}, n int) interface{} //creates a slice with `n` elements dropped from the beginning when n > 0, or `n` elements dropped from the ending when n < 0
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 Filter(slice, function interface{}) interface{} //filter slice, function signature should be func(index int, value interface{}) bool
func Find(slice, function interface{}) interface{} //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(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 FlattenDeep(slice interface{}) interface{} //flattens slice recursive
func IntSlice(slice interface{}) ([]int, error) //convert value to int slice
func InterfaceSlice(slice interface{}) []interface{} //convert value to interface{} slice