iter: Generic, lazy iterators for Go 1.18

This page summarizes the projects mentioned and recommended in the original post on /r/golang

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
  • iter

    Package iter provides generic, lazy iterators, functions for producing them from primitive types, as well as functions and methods for transforming and consuming them. (by mtoohey31)

  • The reason why I decided on the inner/outer architecture was because interface objects can't be used as recievers to methods (as far as I understand). As a result, my initial implementation, which didn't have this structure, was limited to functions instead of methods, which made code where iterator methods were chained extremely unreadable, since it was difficult to tell which order they were being applied in. It's a tradeoff, but I think the readability might be worth it. Do you have any ideas for alternative workarounds?

  • go

    The Go programming language

  • Also, can anyone explain the error "instantiation cycle" to me? I have two methods commented for which this was occuring: Position in iter.go, and ZipEndo in zip.go, and I'm not sure what this error means, or why it occurs, since the corresponding function implementation (Zip) of ZipEndo has no such problem. I don't believe it's an implementation bug in the tuple package, since I was originally using my own simple 2-value tuple struct and the exact same error ocurred. The only thing I can find about it online is this post, but I'm not sure how the answer there applies to either of my cases...

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
  • gtools

    Generic tools for go 1.18+

  • Looks good Do you benchmark it vs for loop? Recently I am wrote pretty similar lib but using functions for all(filter, ForEach etc): gtools Maybe you will find something for yours lib

  • go-iterator

    Discontinued Go 1.18 generics iterator experiment

  • Regarding call chaining, it is still possible to chain things with operations that return different types, but they have to be done with functions instead of methods, so the result is still the same, just it's a little less readable. There is a generic iterator implementation by polyfloyd that doesn't support method chaining, but imo being able to chain iterators is one of their biggest strengths, since implementing lazy evaluation manually for a single operation isn't that difficult, its when you need to perform multiple kinds of manipulations that it gets messy.

  • go-generic

    A collection of experiments using Go Generics coming out in Go 1.18

  • I did some experimenting of my own and came up with this design: https://github.com/qualidafial/go-generic/tree/master/iter

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts