Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's just the visitor pattern, taught in software engineering 101. A function that takes a callback function that gets called for each visited value. Nothing strange about it. Many standard library functions such as sync.Map.Range or filepath.Walk have always used it. The new thing is that it now gets easier to use on the caller side.


The sync.Map.Range, filepath.Walk and other similar functions with visitor pattern in standard Go packages will remain there forever because of backwards compatibility. This means that new functions must be added to standard Go packages in order to be able to use them with iterators starting from Go 1.23. This complicates Go without reasonable benefit:

- You need to be able maintaining code with multiple ways to iterate over various collections in standard Go packages.

- You need to spend time on deciding which approach for iteration to use when you write new code.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: