News for hackers. Stuff that matters.
Re:Go 1.18 Beta 1 is available, with generics by kortex on Wednesday December 15, 2021 @09:44AM (#29566567)
I've wanted a Result type I could map over in Go as soon as I saw the idea. But someone recently pointed out, without pattern matching and early return, it's kind of nerfed. Not sure I totally agree (I think it'd still be awesome to have Result, if only for .map()), but I see their point.

I disagree that it would be without sacrifice. That's kind of the whole point.

Unless I'm missing something, go has iterators with for loops.

Re:Go 1.18 Beta 1 is available, with generics by lucian1900 on Wednesday December 15, 2021 @09:48AM (#29566638)
Go switches with exhaustion checks like in [1] would go a long way. An early return construct would be important as well, though, you're right.

Go's for loops can only iterate over builtin types: slices, maps, channels, etc. You can't produce a custom type that is to be iterated over.

1. https://github.com/BurntSushi/go-sumtype