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

Converting binary operations into operations that work on lists

Consider the following operation:

1 + 2 + 3   ⇒   [1,2,3] |> List.reduce(+)

Instead of having to write all that code where we type a number, type a +, type another number, and we can feed a list of numbers into our reduce function that applies the + operation to each item and accumulates the sum.

Here's an example of appending strings:

"a" + "b" + "c"   ⇒   ["a", "b", "c] |> List.reduce(+)

What was the neutral/identity element used in each of the preceding examples?

The preceding code is F# code. The |> symbol is just a pipe symbol, like we use in a Unix terminal. It allows us to pipe the list of integers [1,2,3] or a list strings ["a", "b", "c"]  into List.reduce(+). The greater than ...
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