Map and filter

The next code example demonstrates the use of a few standard intermediate functions: map and filter.

The code in this example can be copy/pasted into The Go playground, which is a service that takes your Go program, compiles, links, and runs your program with the latest version of Go inside a sandbox and then returns the output to the screen. You can find it at https://play.golang.org/.

Executable commands must always use package main. We can separate each import statement on a separate line for readability.

External packages can be referenced using their remote GitHub repository path. We can preface long package names with a shorter alias. The go_utils package can now be referenced with the u letter. Note that if we aliased ...

Get Learning Functional Programming in Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.