DEV Community

Cover image for Go2: Map and Filter with Generics
Swastik Baranwal
Swastik Baranwal

Posted on

8 1

Go2: Map and Filter with Generics

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!

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️