Relative Content

Tag Archive for gogenerics

Generic methods in go

Coming from Java and dipping my toes into Go’s implementation of generics a bit…

Inference of generic types of an interface

Consider the following code where we create a pipeline. The pipeline is made of Steps. Step is an interface with two struct that implement it; firstStep and followingStep. At each step a function is applied on the input to infer the output. The followingStep contains an input and an output but firstStep only contains an output. The code uses generics, where types are inferred from the previous step and from the function that will, at each step, process the from into the to.

Generics for methods

In the following code, I define a Pipe struct that help use pipe the result of one function into another function.