10.2 How does a function factory work?

How does it work? | Credits: kakaakigas.com/how-it-works/

Figure 10.2: How does it work? | Credits: kakaakigas.com/how-it-works/

power1 <- function(exp) {
  function(x) {
    x ^ exp
  }
}

square <- power1(2)
cube <- power1(3)

power1() is the function factory and square() and cube() are manufactured functions.