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) S

Parameters & Attributes

NameTypeDescription
sSInput slice; may share its backing array.
delfunc(E) boolPredicate 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 }))}
Go Reference