Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert basic operators #43

Open
angelolloqui opened this issue Nov 16, 2017 · 4 comments
Open

Convert basic operators #43

angelolloqui opened this issue Nov 16, 2017 · 4 comments

Comments

@angelolloqui
Copy link
Owner

angelolloqui commented Nov 16, 2017

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)
@angelolloqui
Copy link
Owner Author

angelolloqui commented Feb 8, 2019

Continuing conversation from #89, I believe this conversion can be added by:

  1. Changing the swift func into a method extension on the first argument type
  2. Remove the first argument and replace tokens with its name by copies with this
  3. Add the operator keyword
  4. Map basic operators to their names (+ -> plus, - -> minus,... https://kotlinlang.org/docs/reference/operator-overloading.html)

@torlangballe
Copy link
Collaborator

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?

@angelolloqui
Copy link
Owner Author

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

@torlangballe
Copy link
Collaborator

torlangballe commented Feb 8, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants