- Swift Functional Programming(Second Edition)
- Dr. Fatih Nayebi
- 148字
- 2021-07-02 23:54:26
Closures
Closures are self-contained blocks of code that provide a specific functionality and can be stored, passed around, and used in the code. Closures are the equivalent of blocks in C and Objective-C. Closures can capture and store references to any constants and variables from the context in which they are defined. Nested functions are special cases of closures.
Closures are reference types that can be stored as variables, constants, and type aliases. They can be passed to and returned from functions.
The following examples present different declarations of closures in Swift from the website, http://goshdarnclosuresyntax.com:
// As a variable:
var closureName: (parameterTypes) -> (returnType)
//As a type alias:
typealias closureType = (parameterTypes) -> (returnType)
//As an argument to a function call:
func Name({ (ParameterTypes) -> (ReturnType) in statements })
Closures and first-class, higher-order, and pure functions will be covered in detail in Chapter 2, Functions and Closures.
- 計(jì)算機(jī)綜合設(shè)計(jì)實(shí)驗(yàn)指導(dǎo)
- DB29forLinux,UNIX,Windows數(shù)據(jù)庫管理認(rèn)證指南
- SQL Server入門經(jīng)典
- Python數(shù)據(jù)分析、挖掘與可視化從入門到精通
- 分布式數(shù)據(jù)庫系統(tǒng):大數(shù)據(jù)時(shí)代新型數(shù)據(jù)庫技術(shù)(第3版)
- 圖解機(jī)器學(xué)習(xí)算法
- SQL查詢:從入門到實(shí)踐(第4版)
- Hadoop大數(shù)據(jù)實(shí)戰(zhàn)權(quán)威指南(第2版)
- Python醫(yī)學(xué)數(shù)據(jù)分析入門
- 大數(shù)據(jù)Hadoop 3.X分布式處理實(shí)戰(zhàn)
- 數(shù)據(jù)架構(gòu)與商業(yè)智能
- 數(shù)據(jù)庫技術(shù)及應(yīng)用教程
- 大數(shù)據(jù)技術(shù)入門
- Flutter Projects
- R語言數(shù)據(jù)挖掘