- Swift Functional Programming(Second Edition)
- Dr. Fatih Nayebi
- 173字
- 2021-07-02 23:54:33
Custom operator definition
We can define custom operators using the following syntax:
operatorType operator operatorName { }
Here, operatorType can be one of the following:
- prefix
- infix
- postfix
Custom infix operators can also specify a precedence and an associativity:
infix operator operatorName { associativity left/right/none precedence}
The possible values for associativity are left, right, and none. Left-associative operators associate to the left if written next to other left-associative operators of the same precedence. Similarly, right-associative operators associate to the right if written next to other right-associative operators of the same precedence. Non-associative operators cannot be written next to other operators with the same precedence.
The associativity value defaults to none if it is not specified. The precedence value defaults to 100 if it is not specified.
Any custom operator defined with the preceding syntax will not have an existing meaning in Swift; therefore, a function with operatorName as its name should be defined and implemented. In the following section, we will examine an example of custom operator definition with its respective function definition.
- 公有云容器化指南:騰訊云TKE實戰與應用
- 數據庫技術與應用教程(Access)
- SQL Server 2012數據庫技術與應用(微課版)
- 企業級數據與AI項目成功之道
- 數據科學實戰指南
- 數據庫應用系統開發實例
- Python數據分析從小白到專家
- 智慧城市中的大數據分析技術
- 數據庫原理與設計實驗教程(MySQL版)
- Python 3爬蟲、數據清洗與可視化實戰
- Hands-On Deep Learning for Games
- 智能與數據重構世界
- 從Lucene到Elasticsearch:全文檢索實戰
- Swift Functional Programming(Second Edition)
- Unity for Architectural Visualization