Compare commits

..

No commits in common. "main" and "v0.0.8" have entirely different histories.
main ... v0.0.8

3 changed files with 11 additions and 39 deletions

View File

@ -9,30 +9,3 @@ func Filter[T any](slice []T, f func(T) bool) []T {
}
return ret
}
func FindFirst[T any](slice []T, f func(T) bool) (T, bool) {
for _, v := range slice {
if f(v) {
return v, true
}
}
return *new(T), false
}
func FindFirstIndex[T any](slice []T, f func(T) bool) (int, bool) {
for i, v := range slice {
if f(v) {
return i, true
}
}
return -1, false
}
func FindLastIndex[T any](slice []T, f func(T) bool) (int, bool) {
for i := len(slice); i >= 0; i-- {
if f(slice[i]) {
return i, true
}
}
return -1, false
}

12
of.go
View File

@ -14,15 +14,3 @@ func OfMap[K comparable, V, T any](m map[K]V, unmapper func(K, V) T) []T {
}
return out
}
// UnmapKey is an unmapper function which returns the map key only
// and discards its value. It is supposed to be used with OfMap
func UnmapKey[K comparable, V any](key K, _ V) K {
return key
}
// UnmapValue is an unmapper function which returns the map value only
// and discards its key. It is supposed to be used with OfMap
func UnmapValue[K comparable, V any](_ K, value V) V {
return value
}

11
search.go Normal file
View File

@ -0,0 +1,11 @@
package slices
func Search[T any](slice []T, f func(a, b T) T) T {
if len(slice) == 0 {
return *new(T)
}
value := slice[0]
Each(slice, func(v T) { value = f(value, v) })
return value
}