-
Notifications
You must be signed in to change notification settings - Fork 122
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
Allow currency parsing from implicit context #330
Allow currency parsing from implicit context #330
Conversation
This adds new method in the Currency companion to parse a Currency from a String given a MoneyContext. The method returns a Try[Currency], which is a Failure when the string code is not found in the set of currencies available in the MoneyContext. It also makes all methods in the Money companion that used to parse the currency symbol directly use instead the Currency companion and receive an implicit MoneyContext.
It looks like I missed this #305 before creating this PR. The comment there:
I agree with @estsauver when he says that the expected usage would be to have the context passed implicitily. Either way, I think the most important point would be to stop using the default context on those operations. Hope to hear some input on this. |
* master: Fixed Temperature's toString so it adds the space for the non-degree Kelvin unit, but keeps out the space for others. Also updated the TemperatureSpec to reflect this change. Changed the Kelvin symbol from "°K" to "K"
Hi there, |
@garyKeorkunian I've checked the current master (with this PR merged) and it seems like #323 is still a problem. |
Also getting that #323 when running tests |
This PR adds a companion object to
Currency
whoseapply
receives a currency code String, an implicitMoneyContext
and returns aTry[Currency]
.It also changes the methods in
Money
companion that used to parse a currency from a String and relied solely on thedefaultMoneyContext
to fetch the correspondingCurrency
value: these methods now receive an implicitMoneyContext
and use the newCurrency.apply
which, I think, should solve #296.For my use case, these modifications are useful when working with domain models that specify some
Currency
, that must be parsed from JSON, and when loadingCurrency
from typesafe config (using PureConfig).