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

Refactor CurrencyMint #21

Merged
merged 1 commit into from
Feb 29, 2020
Merged

Refactor CurrencyMint #21

merged 1 commit into from
Feb 29, 2020

Conversation

Mordil
Copy link
Member

@Mordil Mordil commented Jan 25, 2020

Motivation:

The ISO 4217 standard defines a reasonable "default" currency of XXX - "No currency" - that can be used to remove the need for optionality of the make result.

Developers also would want to be able to easily work with CurrencyMint without having to do a bunch of boilerplate with their own custom types.

In addition, the ergonomics of working with CurrencyMint are lacking where Swift's literal syntax can assist and reduce code duplication.

Modifications:

  • Add CurrencyIdentifier for CurrencyMint to use for its factory methods
  • Add standard static singleton for CurrencyMint that resolves "XXX" by default
  • Change CurrencyMint to store a closure for resolving a default currency type when ISO 4217 lookup fails

Result:

Working with CurrencyMint will be easier and more native, especially when integrating custom currency types.

@Mordil Mordil requested a review from thonydam January 25, 2020 07:52
@codecov
Copy link

codecov bot commented Jan 25, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@cecf3a7). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master      #21   +/-   ##
=========================================
  Coverage          ?   89.65%           
=========================================
  Files             ?        6           
  Lines             ?      174           
  Branches          ?        0           
=========================================
  Hits              ?      156           
  Misses            ?       18           
  Partials          ?        0
Impacted Files Coverage Δ
Sources/Currency/CurrencyMint.swift 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cecf3a7...9c78af4. Read the comment docs.

@Mordil
Copy link
Member Author

Mordil commented Jan 25, 2020

@thonydam This is just something that randomly got in my head. It's a super low priority thing to look at.

Let me know what you think.

@Mordil Mordil force-pushed the refactor-mint branch 2 times, most recently from 0a750bb to 50b00d8 Compare January 25, 2020 08:16
@codeclimate
Copy link

codeclimate bot commented Feb 24, 2020

Code Climate has analyzed commit 9c78af4 and detected 0 issues on this pull request.

View more on Code Climate.

@Mordil Mordil removed the request for review from thonydam February 29, 2020 03:42
Motivation:

The current implementation of CurrencyMint is highly rigid and requires a ton of support from SwiftCurrency to be of true value.

Cases of custom currencies and quick fallbacks to a default type requires a fair bit of boilerplate code that can be simplified with
an improved re-implementation.

In addition, there were several places of code duplication that are possible to simplify with Swift's literal syntax for easier maintenance.

Modifications:

- Add: `CurrencyIdentifier` for CurrencyMint to use in lookup resolution methods
- Add: `standard` static singleton for CurrencyMint to resolve only ISO 4217 currencies
- Change: `CurrencyMint` to store a fallback lookup closure for 3rd party and default currency resolution

Result:

Developers using CurrencyMint should have an easier time supporting their own currencies, or unsupported/missing ISO 4217 currencies.
@Mordil Mordil added enhancement New feature or request semver-major Require SemVer Major bump labels Feb 29, 2020
@Mordil Mordil merged commit cf39c18 into master Feb 29, 2020
@Mordil Mordil deleted the refactor-mint branch February 29, 2020 05:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request semver-major Require SemVer Major bump
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant