Go 1.27 Just Fixed Our Iterator's Biggest Problem!
Let's work on the iterator chain project and add a generic method in Go 1.27. If you would like to see a quick summary of all the changes in Go 1.27, check out this video: https://youtu.be/RboN0J87NrA 📝 Description Learn how to build a type-changing `MapTo` function for your Go iterator chain, and how Go 1.27's generic methods turn it into a clean `Map` method. This is part three of the iterators mini-series. We start with the pre-1.27 approach, then refactor it into a method on the `Iterator` struct. Here's what you will learn: • Understand why a method-based `Map` can't change types before Go 1.27, and why a standalone MapTo function was needed. • See how `MapTo` builds a lazy, pull-based iterator that wraps the previous stage in the chain. • Discover how Go 1.27 generic methods let Map declare its own type parameter `U`, so one method handles both same-type and type-changing transformations. • Keep your chains fluent, for example by turning `*Iterator[int]` into `*Iterator[string]` without breaking the chain. • See why this matters for readability, code organization, and library design. ⏳ Timestamps: 00:00 - Introduction 00:27 - Why a MapTo function? 01:35 - MapTo Implementation 07:45 - Map Implementation 10:25 - Outro 👋 Hey there! If you are new to this channel: Hey 👋 my name is Flo and I am a professional software engineer with a passion for coding in Golang, TypeScript, JavaScript, and Rust. This channel is where I share that passion and dive into the exciting world of software engineering. 📨 Support and Connect! Become a member. https://www.youtube.com/@FloWoelki/membership Discord: https://discord.gg/TnA7drJ X / Twitter: https://x.com/FlorianWoelki LinkedIn: https://www.linkedin.com/in/florian-woelki/ GitHub: https://github.com/FlorianWoelki 📝 Copyright Notice The original Go Gopher was designed by Renée French (Source: https://go.dev/blog/gopher License details: https://creativecommons.org/licenses/by/4.0/). The gopher appearing in this video and thumbnail has been modified from the original design and is based on an illustration from Maria Letta's free-gophers-pack (Source: https://github.com/MariaLetta/free-gophers-pack License: CC0 1.0 Public Domain https://creativecommons.org/publicdomain/zero/1.0/). #go #go127 #method #iterator #chain




Join the discussion
Sign in to join the discussion
Sign in