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

Partial application

Our third option is called partial application. We can accomplish this with currying.

The idea behind currying is to create new, more specific functions from other more general functions by partially applying them.  

Consider that we have have an add function that takes two numbers:

func add(x, y int) int {   return x + y}

We can create another function that returns the add function with one of the parameters pre-inserted. We'll take a simple example of adding one to any other number:

func addOnePartialFn() func(int) int {   return func(y int) int {      return add(1, y)   }}

The results of calling add(1,2) will be the same as calling addOne(2):

func main() {   fmt.Printf("add(1, 2): %d\n", add(1, 2))   addOne := addOnePartialFn() 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