Articles with the tag "generics"

Go Experience Report: Interfaces with Methods that Return Themselves

I want to describe a scenario where there currently isn’t a good solution in Go (at least that I am aware of). Let’s say you have something like the template.Template type with methods like Template.Funcs: type Template struct { *parse.Tree // contains filtered or unexported fields } func (t *Template) Funcs(funcMap FuncMap) *Template If we wanted to use an interface for this type, it is impossible to express in Go now.

Generating data structures that need additional functions

There has been a lot of talk about generics lately in the Go community which as lead to me thinking about them a lot lately. In thinking about generics, my mind instinctively wandered to code generation because that has been my go-to tool when I do need something resembling a generic. In fact, I have written about using code generation to get by without generics in Go in the past.

Using code generation to survive without generics in Go

Learn how to use code generation to create type-safe code (like a Queue or LinkedList) without having to rewrite the same thing over and over again.

Avatar of Jon Calhoun
Articles and Tutorials by
Jon Calhoun

Jon Calhoun is a full stack web developer who teaches about Go, web development, algorithms, and anything programming. If you haven't already, you should totally check out his Go courses.

Previously, Jon worked at several statups including co-founding EasyPost, a shipping API used by several fortune 500 companies. Prior to that Jon worked at Google, competed at world finals in programming competitions, and has been programming since he was a child.

Recent Articles All Articles Mini-Series Progress Updates Tags About Me Go Courses

©2024 Jonathan Calhoun. All rights reserved.