- 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.
- 計算機組成原理與接口技術:基于MIPS架構實驗教程(第2版)
- ETL數據整合與處理(Kettle)
- Visual Studio 2015 Cookbook(Second Edition)
- 虛擬化與云計算
- 大數據:規劃、實施、運維
- 數據要素五論:信息、權屬、價值、安全、交易
- Lean Mobile App Development
- Enterprise Integration with WSO2 ESB
- Python醫學數據分析入門
- 大數據架構商業之路:從業務需求到技術方案
- Proxmox VE超融合集群實踐真傳
- Oracle RAC日記
- Instant Autodesk AutoCAD 2014 Customization with .NET
- SQL Server 2008寶典(第2版)
- Unity Game Development Blueprints