-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
set: Use type parameters for the Set, Rules, and Iterator types
Although we're not yet making great use of this due to the fact that the top-level "set rules" are still for interface{} anyway, this is a step towards doing something a bit more specific later, and for now it allows some type-safety around _path sets_ in particular.
- Loading branch information
1 parent
97bafac
commit 74095df
Showing
18 changed files
with
187 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
package set | ||
|
||
type Iterator struct { | ||
vals []interface{} | ||
type Iterator[T any] struct { | ||
vals []T | ||
idx int | ||
} | ||
|
||
func (it *Iterator) Value() interface{} { | ||
func (it *Iterator[T]) Value() T { | ||
return it.vals[it.idx] | ||
} | ||
|
||
func (it *Iterator) Next() bool { | ||
func (it *Iterator[T]) Next() bool { | ||
it.idx++ | ||
return it.idx < len(it.vals) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.