November 2017
Intermediate to advanced
670 pages
17h 35m
English
We start with our typical package main and import statements and the main() function:
package mainimport ( . "functor" "fmt")func main() {
Note that we preface our internal functor package (found in the src directory) with a dot. That allows us to refer to symbols that it exports, such as Functor and Map.
First, we call our Functor method and pass in our slice of AmHours. Functor wraps our hours structure in a function of type ClockFunctor:
fmt.Println("initial state :", Functor(AmHoursFn()))
Here's the output:
initial state : [1 2 3 4 5 6 7 8 9 10 11 12]
The Functor function is what connects our two worlds: the world of AM hours and the world of PM hours (or vice versa). We can say that Functor lowers our hours into a magical box ...