- 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=1739056223-4sNw4mjbFHJszgDNk0GC4cXP7bpFKjVi-0-3161b9adc21ef0c3bdf5130163683b93)
Function composition is the cornerstone to pure FP; It's what allows us to build larger abstractions out of smaller ones.