Files
lo/docs/data/core-coalescemaporempty.md
T
2025-10-06 17:15:49 +02:00

955 B

name, slug, sourceRef, category, subCategory, signatures, playUrl, variantHelpers, similarHelpers, position
name slug sourceRef category subCategory signatures playUrl variantHelpers similarHelpers position
CoalesceMapOrEmpty coalescemaporempty type_manipulation.go#L207 core type
func CoalesceMapOrEmpty[K comparable, V any](v ...map[K]V) map[K]V
https://go.dev/play/p/Gyo9otyvFHH
core#type#coalescemaporempty
core#type#coalesce
core#type#coalesceorempty
core#type#coalesceslice
core#type#coalescesliceorempty
core#type#coalescemap
core#type#empty
155

Returns the first non-empty map from the provided arguments, or an empty map if all arguments are empty.

result := lo.CoalesceMapOrEmpty(map[string]int{}, map[string]int{"a": 1}, map[string]int{"b": 2})
// map[string]int{"a": 1}

result = lo.CoalesceMapOrEmpty(map[string]int{}, map[string]int{})
// map[string]int{}

result = lo.CoalesceMapOrEmpty(map[int]string{}, map[int]string{1: "one"}, map[int]string{2: "two"})
// map[int]string{1: "one"}