Go composable iterator functions

submited by
Style Pass
2024-02-10 11:30:03

I am excited about the future of Go, trying to balance simplicity with new features and functionality. In particular, I am really looking forward to function interators.

A few years back, I wrote a small, experimental library for lazy evaluation of collection can that can be found here called gnsource. The idea was to support lazy evaluated, composable pieces to pipeline data. Now, this is a feature coming to Go soon and that can be tried out already in experimental mode.

A function iterator is a function that can be used in range loops in Go. Until now, range loops can only be used in a very particular set of types: slices, maps, bytes, channels, string. Now, we will be able to range loop over any function iterator.

Instead of going over the mighty details of how this work, I will instead direct you to https://bitfieldconsulting.com/golang/iterators for the details because I want to focus on how to use this instead of behind scenes bits.

The use of generics and function iterators together makes possible a few things I was trying to achieve when writing gnsource.

Leave a Comment