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

FilterFunc

In the types.go file, we see its definition:

FilterFunc func(string) bool

Looking back at the line in main.go, we see that we use the ByMake filter function:

PrintCars("ByMake - Honda", cars.Filter(ByMake("Honda")))

The ByMake function is defined in the cars.go file:

func ByMake(make string) FilterFunc {       return func(car string) bool {              return s.Contains(car, make)       }}

The ByMake function is a HOF because it returns a function. Recall that Filter is a HOF because it accepts a function. In this case, ByMake is that function, fn, as we will see in the next section.

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