Filter returns a new slice containing all elements of the slice that satisfy the predicate function.
(s []T, f func(T) bool)
| 12 | |
| 13 | // Filter returns a new slice containing all elements of the slice that satisfy the predicate function. |
| 14 | func Filter[T any](s []T, f func(T) bool) []T { |
| 15 | r := make([]T, 0, len(s)) |
| 16 | for _, v := range s { |
| 17 | if f(v) { |
| 18 | r = append(r, v) |
| 19 | } |
| 20 | } |
| 21 | return r |
| 22 | } |
| 23 | |
| 24 | // Equal returns true if all elements are equal. |
| 25 | func Equal[T comparable](first, second T, rest ...T) bool { |
no outgoing calls