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

Allow currency parsing from implicit context #330

Conversation

thyandrecardoso
Copy link
Contributor

This PR adds a companion object to Currency whose apply receives a currency code String, an implicit MoneyContext and returns a Try[Currency].

It also changes the methods in Money companion that used to parse a currency from a String and relied solely on the defaultMoneyContext to fetch the corresponding Currency value: these methods now receive an implicit MoneyContext and use the new Currency.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 loading Currency from typesafe config (using PureConfig).

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.
@thyandrecardoso
Copy link
Contributor Author

It looks like I missed this #305 before creating this PR.
Sorry about this.

The comment there:

I'm not sure about this, passing this as an implicit sounds like an overstretch of implicit. Wouldn't you rather pass it as a plain param?

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.
Thanks!

* 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"
@thyandrecardoso
Copy link
Contributor Author

Hi there,
Did someone have the opportunity to take a look into this PR?

@psttf
Copy link

psttf commented Feb 12, 2019

@garyKeorkunian I've checked the current master (with this PR merged) and it seems like #323 is still a problem.

@jchapuis
Copy link

Also getting that #323 when running tests

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

Successfully merging this pull request may close these issues.

4 participants