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

Use of expressions

Use of expressions (rather than statements) means that in FP, we pass a value to a function that typically transforms it in some way and then returns a new value. Since FP functions have no side effects, an FP function that does not return a value is useless and a sign of code smell.

In Chapter 1, Pure Functional Programming in Go, we saw that imperative programming focuses on the step-by-step mechanics of how a program operates, whereas in declarative programming, we declare what we want the results to be.

Here's an example of imperative programming:

var found boolcar_to_look_for := "Blazer"cars := []string{"Accord", "IS250", "Blazer" }for _, car := range cars {       if car == car_to_look_for {              found = true;       }}fmt.Printf(
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