Allow %Currency{}
structs in currency_for_code/3
#4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is part of a series of PRs that aim to improve performance by allowing both
%Cldr.Number.Format.Options{}
structs to be passed as options in place of keyword lists, and to add support for%Cldr.Currency{}
structs as alternative for currency codes.#4 (this PR)
elixir-cldr/cldr_numbers#18
kipcole9/money#127
This PR adds support to pass a
%Cldr.Currency
struct directly, and will return it if it's passed tocurrency_for_code/3
. Sincecurrency_for_code/3
is relatively complex, and iterates over currencies (which may be something that can be addressed in a future PR, replacing it with a keyed lookup via a map), this change attempts to offer developers a way to pass the currency struct, already resolved. This in turn made a real-world impact when we ran this in a tight loop. In our use-case, we know the currencies beforehand, and we pre-resolve these currencies. We take the trade-off between slighly higher compile time, and much faster runtime performance.I ran this benchmark:
https://gist.github.com/jeroenvisser101/32deb85f50fe76f8cd5d48049591e355