Chaining functions through dot notation
Chaining functions through dot notation is not a unique concept to functional programming. In fact, many object-oriented patterns such as the builder pattern explicitly do this as well. Before we dive into how we can leverage Go’s type aliases to do this, let’s look at an example in a more object-oriented style of programming before we dive into chaining functions.
Chaining methods for object creation (builder pattern)
We will create a package-private person
object and add some public functions to change the state of the person, although remember that in Go, this is not the best way of instantiating a new object. However, it is the method many traditional object-oriented languages opt for:
type person struct { firstName string lastName string age ...