ExampleSet_FuncMatch demonstrates filtering set elements
()
| 120 | |
| 121 | // ExampleSet_FuncMatch demonstrates filtering set elements |
| 122 | func ExampleSet_FuncMatch() { |
| 123 | numbers := set.Create(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) |
| 124 | |
| 125 | // Find all even numbers |
| 126 | evens := numbers.FuncMatch(func(n, _ int) bool { |
| 127 | return n%2 == 0 |
| 128 | }, 0) |
| 129 | |
| 130 | // Find all numbers greater than 5 |
| 131 | greaterThanFive := numbers.FuncMatch(func(n, threshold int) bool { |
| 132 | return n > threshold |
| 133 | }, 5) |
| 134 | |
| 135 | fmt.Println("Even numbers:", set.ToSliceOrdered(evens)) |
| 136 | fmt.Println("Greater than 5:", set.ToSliceOrdered(greaterThanFive)) |
| 137 | |
| 138 | // Output: |
| 139 | // Even numbers: [2 4 6 8 10] |
| 140 | // Greater than 5: [6 7 8 9 10] |
| 141 | } |
| 142 | |
| 143 | // ExampleCopy demonstrates copying a set |
| 144 | func ExampleCopy() { |
nothing calls this directly
no test coverage detected