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

It's time to run our program

Now, it's time to provide the duck with its starting resources and a list of ponds to swim in and see whether our duck survives to live another day.

Let's assume our duck has five bugs in its belly, which is worth five strokes (we made our ponds and bugs very small to simplify our model):

func main() {       var duck Duck       capabilities := Capabilities{              StrokeBehavior: Foot{},              EatBehavior:    Bill{},              strokes:        5,       }

Our duck's first set of ponds will consist of two ponds. Each supplies only one bug. The first pond requires three strokes to reach the other side. The second pond requires two strokes:

ponds := []Pond{       {BugSupply: 1, StrokesRequired: 3},       {BugSupply: 1, StrokesRequired: 2},}duck.SwimAndEat(&capabilities, &capabilities.strokes, ...
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