Skip to Content
Learning Functional Programming in Go
book

Learning Functional Programming in Go

by Lex Sheehan
November 2017
Intermediate to advanced
670 pages
17h 35m
English
Packt Publishing
Content preview from Learning Functional Programming in Go

Nums revisited

Remember those four numerics types that we implemented a Sum method for without generics? Let's revisit that code and see if we can improve our code base now that we know about gen:

cd <DEVDIR>/learn-fp-go/4-purely-functional/ch11-functor-monoid/04_generics_nums. initglide-update

Note that we need to run glide-update so that the vendors directory will be created for us. It will first be placed in our GOPATH so that when we run the next command, the gen package and its dependencies will go in our vendors directory rather than our project’s src directory:

go get github.com/clipperhouse/gen

Now, let's cd to ~/dev/04_generics_nums/src/num and run gen:

cd src/num;gen;cd -

We can see that gen created four files, one for each slice ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Functional Programming

Learning Functional Programming

Jack Widman

Publisher Resources

ISBN: 9781787281394Supplemental Content