B.5 Functional programming

# https://cran.r-project.org/web/packages/lambda.r/index.html
library(lambda.r)

B.5.1 Helper function

# Helper to generate parameter names
generate_names <- function(name, count) {
  if (count == 1) name else c(name, paste0(name, seq_len(count - 1)))
}
  
# Generate parameter names
generate_names("mu", 3)
## [1] "mu"  "mu1" "mu2"