SwiftKotlin
SwiftKotlin copied to clipboard
Convert basic operators
Swift allows for custom operators. In Kotlin, operators are restricted to: https://kotlinlang.org/docs/reference/operator-overloading.html
Transform the operators that have a Kotlin counterpart. Example:
public func + (left: Price, right: Price) -> Price {
return Price(amount: left.amount + right.amount, currency: left.currency)
}
public func - (left: Price, right: Price) -> Price {
return Price(amount: left.amount - right.amount, currency: left.currency)
}
Translates to:
operator fun Price.plus(price: Price) =
Price(amount = this.amount + price.amount, currency = this.currency)
operator fun Price.minus(price: Price) =
Price(amount = this.amount - price.amount, currency = this.currency)
Continuing conversation from #89, I believe this conversion can be added by:
- Changing the swift func into a method extension on the first argument type
- Remove the first argument and replace tokens with its name by copies with
this
- Add the
operator
keyword - Map basic operators to their names (
+
->plus
,-
->minus
,... https://kotlinlang.org/docs/reference/operator-overloading.html)
This would be great. Since they were outside of class/struct in swift I just went for a simple hack, but this would be clean and perfect. Maybe you do it?
Yeah, it is in the scope of changes I want to make, but to be honest, it has been open for more than 1 year already. I am not finding all the time I would like to implement all the issues (and the list is long). So yes, I hope I will eventually implement it myself but I can not promise when.
If this is important for you, please let me know so I will try to prioritize over others
I can work my way through all other changes first. Can always do a pull request and see if I can do it how you want too if it gets to that, but no hurry yet.
tor
On 8 Feb 2019, at 12:52, Angel G. Olloqui [email protected] wrote:
Yeah, it is in the scope of changes I want to make, but to be honest, it has been open for more than 1 year already. I am not finding all the time I would like to implement all the issues (and the list is long). So yes, I hope I will eventually implement it myself but I can not promise when.
If this is important for you, please let me know so I will try to prioritize over others
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/angelolloqui/SwiftKotlin/issues/43#issuecomment-461779406, or mute the thread https://github.com/notifications/unsubscribe-auth/AB-irn0eSYgbstGC7uq9SlXP81naynb6ks5vLWT1gaJpZM4QgO2d.