- 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.
- 數據之巔:數據的本質與未來
- Developing Mobile Games with Moai SDK
- Voice Application Development for Android
- PySpark大數據分析與應用
- Learn Unity ML-Agents:Fundamentals of Unity Machine Learning
- 大數據Hadoop 3.X分布式處理實戰
- INSTANT Cytoscape Complex Network Analysis How-to
- 企業級數據與AI項目成功之道
- Flutter Projects
- Chef Essentials
- Unreal Engine Virtual Reality Quick Start Guide
- SQL Server 2008寶典(第2版)
- 大數據分析:R基礎及應用
- Access 2016數據庫應用基礎
- 大數據計算系統原理、技術與應用