Polymorphism with Functions in Go
Having a function implement an interface can be really useful when testing or programming Go code. Being able to do this allows you to have a data structure such as a map or an array hold both functions and structs that implement the interface. Let’s consider the following example, imagine that you are writing a data pipeline where you have to populate the various fields inside a car object. In order to populate these fields you have to fetch the information from various sources. You might have to query your internal database, a third party database, and other third party websites. In order to do this you decide to have a Transformer interface that takes in a Car and returns a Car with new information. The struct and the code look something like this:
crro