2024-01-22 13:20:07 -05:00
|
|
|
## Changes to the language {#language}
|
|
|
|
|
2024-06-04 16:06:12 -07:00
|
|
|
<!-- go.dev/issue/61405, CL 557835, CL 584596 -->
|
2024-06-05 15:21:25 -04:00
|
|
|
Go 1.23 makes the (Go 1.22) ["range-over-func" experiment](/wiki/RangefuncExperiment) a part of the language.
|
2024-06-04 16:06:12 -07:00
|
|
|
The "range" clause in a "for-range" loop now accepts iterator functions of the following types
|
2024-01-22 13:20:07 -05:00
|
|
|
|
2024-06-05 15:21:25 -04:00
|
|
|
func(func() bool)
|
|
|
|
func(func(K) bool)
|
|
|
|
func(func(K, V) bool)
|
2024-06-04 16:06:12 -07:00
|
|
|
|
2024-06-05 15:21:25 -04:00
|
|
|
as range expressions.
|
|
|
|
Calls of the iterator argument function produce the iteration values for the "for-range" loop.
|
2024-06-15 18:00:19 -04:00
|
|
|
For details see the [iter] package documentation and the [language spec](/ref/spec#For_range).
|
|
|
|
For motivation see the 2022 ["range-over-func" discussion](/issue/56413).
|
2024-06-04 16:29:30 -07:00
|
|
|
|
|
|
|
<!-- go.dev/issue/46477, CL 566856, CL 586955, CL 586956 -->
|
|
|
|
Go 1.23 includes preview support for [generic type aliases](/issue/46477).
|
|
|
|
Building the toolchain with `GOEXPERIMENT=aliastypeparams` enables this feature.
|