Cover image for Go2: Map and Filter with Generics

Go2: Map and Filter with Generics

delta456 profile image Swastik Baranwal ・1 min read

Go plans to add generics in their next big release since 2016 and they have been working upon the syntax so that it matches with current semantics.

In June 2020 they had released a draft for how about they have planned the syntax to match with their semantics.

One of the problems of Go which it was a lot criticized was that it had never had map and filter in built which is a lot used for functional programming. Gophers had to write a for loop to achieve but Rob Pike had written a filter package to achieve this but it contains a lot of boilerplate and he suggests to use for loop. With Generics map and filter can be implemented quiet easily.

While going through the Go Reddit. I had found this code which implements map, filter, any and all in Go with Generics. You must have noticed that they use [T] instead of <T> for denoting them. They are currently testing and asking for feedback as <T> doesn't match with Go semantics. You can find the thread here.

I hope Go2 will be best release of Go Language ever!


markdown guide