- Swift Functional Programming(Second Edition)
- Dr. Fatih Nayebi
- 168字
- 2021-07-02 23:54:31
Defining and using variadic functions
Swift enables us to define functions with variadic parameters. A variadic parameter accepts zero or more values of a specified type. Variadic parameters are similar to array parameters but they are more readable and can only be used as the last parameter in multi-parameter functions.
As variadic parameters can accept zero values, we will need to check whether they are empty.
The following example presents a function with variadic parameters of the String type:
func greet(names: String...) {
for name in names {
print("Greetings, \(name)")
}
}
// To call this function
greet(names: "Josee", "Jorge") // prints twice
greet(names: "Josee ", "Jorge ", "Marcio") // prints three times
The most boring part of the chapter is almost over. Seriously, we needed to master the Swift function/method syntax and we will see the benefits in upcoming chapters. If you speed read or skipped previous sections, it is okay. The upcoming sections are going to be essential for FP so they need more attention.
- 程序員修煉之道:從小工到專家
- Hands-On Machine Learning with Microsoft Excel 2019
- Architects of Intelligence
- R數據科學實戰:工具詳解與案例分析(鮮讀版)
- Lean Mobile App Development
- Hadoop 3.x大數據開發實戰
- 數亦有道:Python數據科學指南
- 改變未來的九大算法
- Doris實時數倉實戰
- Python數據分析從小白到專家
- SQL Server 2008寶典(第2版)
- 企業級大數據項目實戰:用戶搜索行為分析系統從0到1
- 領域驅動設計精粹
- 推薦系統全鏈路設計:原理解讀與業務實踐
- 深入理解Flink:實時大數據處理實踐