Standard library / maps

maps.DeleteFunc()

Deletes entries satisfying the predicate in place. Predicate calls follow unspecified map order. Expected stdout: '1 1\n'.

Formal Syntax & Structure

go syntaxgo
func DeleteFunc[M ~map[K]V, K comparable, V any](m M, del func(K, V) bool)

Parameters & Attributes

NameTypeDescription
mMInput map.
delfunc(K, V) boolPredicate identifying entries or elements to remove.

Working Example

Example Snippetgo
package main
import (  "fmt"  "maps")
func main() {  a := map[string]int{"a": 1, "b": 2}  maps.DeleteFunc(a, func(k string, v int) bool { return v%2 == 0 })  fmt.Println(len(a), a["a"])}
Go Reference