-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add plus/minus methods as aliases for add/subtract transformations #10
Comments
Hi James, thanks. I will check this article, and I will see to what extend this can be incorporated into the code. |
@jamesdh Feature is implemented and it will be included in the next planned release. You can also test it now, using code from the branch: // Temperature examples
def t1 = Temperature.ofCelsius(20)
def t2 = Temperature.ofCelsius(10)
def t3 = Temperature.ofKelvins(303.15) // =30 oC
// Adding & subtracting: The same unit
def t4 = t1 + t2
def t5 = t1 - t2
def t6 = t1 + 15.5;
println t4 // Temperature{30.0°C}
println t5 // Temperature{10.0°C}
println t6 // Temperature{35.5°C}
// Adding & subtracting: Different units of the same quantity, resolving to unit type of the first addend.
def t7 = t1 + t3
def t8 = t1 - t3
println t7 // Temperature{50.0°C}
println t8 // Temperature{-10.0°C}
// Multiply
def t9 = t1 * t2
def t10 = t1 * 2
println t9 // will resolve to double = 200.0
println t10 // Temperature{40.0°C}
// Divide
def t11 = t1 / t2
def t12 = t1 / 2
println t11 // will resolve to double = 2.0
println t12 // Temperature{10.0°C} For multiply and divide - on attempt to divide or multiply by other quantity it resolves to double. This is because that kind of operations changes the Unit type and at this point there is no resolver implemented to determine, that for i.e: division of Newton over Area in m2 should be resolved to Pressure in Pascals. |
You are awesome. Thank you for this! Love the project! |
I am very happy you like my project! Feature added in release: v2.0.0 - Frameworks support: Spring and Quarkus |
When using this library with Groovy, including
plus()
andminus()
methods would allow one to more succinctly perform transformations, e.g.Here's a blog post with a bit more info and also the official docs
The text was updated successfully, but these errors were encountered: