ExampleSet_ToSlice demonstrates custom sorting with comparison function
()
| 211 | |
| 212 | // ExampleSet_ToSlice demonstrates custom sorting with comparison function |
| 213 | func ExampleSet_ToSlice() { |
| 214 | words := set.Create("go", "rust", "python", "javascript") |
| 215 | |
| 216 | // Sort by length (shortest first) |
| 217 | byLength := words.ToSlice(func(a, b string) int { |
| 218 | return len(a) - len(b) |
| 219 | }) |
| 220 | |
| 221 | fmt.Println("By length:", byLength) |
| 222 | |
| 223 | // Output: |
| 224 | // By length: [go rust python javascript] |
| 225 | } |
| 226 | |
| 227 | // ExampleNew demonstrates creating an empty set and adding elements |
| 228 | func ExampleNew() { |