MCPcopy
hub / github.com/minio/minio-go / ExampleSet_nestedComparable

Function ExampleSet_nestedComparable

pkg/set/example_test.go:337–363  ·  view source on GitHub ↗

ExampleSet_nestedComparable demonstrates using Set with nested comparable structs

()

Source from the content-addressed store, hash-verified

335
336// ExampleSet_nestedComparable demonstrates using Set with nested comparable structs
337func ExampleSet_nestedComparable() {
338 // Define nested comparable types
339 type Coordinate struct {
340 Lat, Lon float64
341 }
342
343 type Location struct {
344 Name string
345 Coords Coordinate
346 }
347
348 places := set.New[Location]()
349
350 places.Add(Location{"Eiffel Tower", Coordinate{48.8584, 2.2945}})
351 places.Add(Location{"Statue of Liberty", Coordinate{40.6892, -74.0445}})
352 places.Add(Location{"Eiffel Tower", Coordinate{48.8584, 2.2945}}) // duplicate
353
354 fmt.Println("Unique places:", len(places))
355
356 // Check if location exists
357 eiffel := Location{"Eiffel Tower", Coordinate{48.8584, 2.2945}}
358 fmt.Println("Has Eiffel Tower:", places.Contains(eiffel))
359
360 // Output:
361 // Unique places: 2
362 // Has Eiffel Tower: true
363}

Callers

nothing calls this directly

Calls 2

AddMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected