Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Find ¶
func Find[M ~map[T]E, T, E comparable](m M, v E) (T, bool)
Find searches for the first key in the map `m` that matches the value `v`. It returns the key and a boolean indicating whether the value was found.
- M is a map type where the key is of type T and the value is of type E. - T represents the key type, E represents the value type.
Example ¶
package main import ( "fmt" "github.com/exonlabs/go-utils/pkg/abc/mapx" ) func main() { m := map[string]int{ "first": 1, "second": 2, "third": 3, } // Find the key for the value 2 key, found := mapx.Find(m, 2) if found { fmt.Println("Found key:", key) } else { fmt.Println("Value not found") } // Find a non-existing value key, found = mapx.Find(m, 4) if !found { fmt.Println("Value not found") } }
Output: Found key: second Value not found
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.