- 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.
- 企業數字化創新引擎:企業級PaaS平臺HZERO
- 大數據技術基礎
- Creating Mobile Apps with Sencha Touch 2
- Effective Amazon Machine Learning
- InfluxDB原理與實戰
- Oracle RAC 11g實戰指南
- 大數據導論
- 大數據營銷:如何讓營銷更具吸引力
- 數據驅動設計:A/B測試提升用戶體驗
- 智能數據分析:入門、實戰與平臺構建
- Lego Mindstorms EV3 Essentials
- 圖數據實戰:用圖思維和圖技術解決復雜問題
- Oracle高性能SQL引擎剖析:SQL優化與調優機制詳解
- Web Services Testing with soapUI
- 大數據數學基礎(R語言描述)