- Learning Functional Programming in Go
- Lex Sheehan
- 92字
- 2021-07-02 23:13:46
Function composition
Function composition is where we combine two smaller functions to create a new function that accomplishes the same goal as the two smaller ones. Both ways get us from an a to c. Below, f1 accepts an a and returns a b. f2 accepts a b and returns a c. We can compose/combine those two functions and get a single function that accepts an a and returns a c:
![](https://epubservercos.yuewen.com/6176FA/19470400908922906/epubprivate/OEBPS/Images/Chapter_58.jpg?sign=1738948995-UHvAfK5E1n06yDzONFYhzhUaePjtzxmt-0-70336a4bdea25d41073fc6dd4ce8da0e)
Function composition is the cornerstone to pure FP; It's what allows us to build larger abstractions out of smaller ones.