- 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.
- GitHub Essentials
- 大數據技術基礎
- 數據庫應用實戰
- 數據庫原理及應用教程(第4版)(微課版)
- Architects of Intelligence
- Effective Amazon Machine Learning
- Modern Programming: Object Oriented Programming and Best Practices
- 計算機信息技術基礎實驗與習題
- Python數據分析、挖掘與可視化從入門到精通
- 智能數據分析:入門、實戰與平臺構建
- 深入淺出Greenplum分布式數據庫:原理、架構和代碼分析
- INSTANT Apple iBooks How-to
- 重復數據刪除技術:面向大數據管理的縮減技術
- Construct 2 Game Development by Example
- 區塊鏈技術應用與實踐案例