Standard library / slices
slices.DeleteFunc()
Removes all matching elements, preserving survivor order and clearing discarded slots. Mutates the backing array. Expected stdout: '[1 3]\n'.
Formal Syntax & Structure
go syntaxgo
func DeleteFunc[S ~[]E, E any](s S, del func(E) bool) SParameters & Attributes
| Name | Type | Description |
|---|---|---|
| s | S | Input slice; may share its backing array. |
| del | func(E) bool | Predicate identifying entries or elements to remove. |
Return Value
S
Removes all matching elements, preserving survivor order and clearing discarded slots. Mutates the backing array.
Working Example
Example Snippetgo
package main
import ( "fmt" "slices")
func main() { fmt.Println(slices.DeleteFunc([]int{1, 2, 3, 4}, func(v int) bool { return v%2 == 0 }))}