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

Add money comparisson #112

Open
totemcaf opened this issue Jul 16, 2022 · 1 comment
Open

Add money comparisson #112

totemcaf opened this issue Jul 16, 2022 · 1 comment

Comments

@totemcaf
Copy link
Contributor

totemcaf commented Jul 16, 2022

There are several methods to compare two Money object but there is no Money.Compare(Money) function.

The proposal is to add a Compare function for Money.

// Compare returns an integer comparing two Money objects
// If Money objects are of different currency, an ErrCurrencyMismatch is returned.
// If both objects are for same currency, their amounts are compared.
// The result will be 0 if a == b, -1 if a < b, and +1 if a > b.
func (m *Money) Compare(om *Money) int {
    if err := m.assertSameCurrency(om); err != nil {
        return false, err
    }

    return m.compare(om), nil
}

I'll provide a PR.

@Rhymond
Copy link
Owner

Rhymond commented Jul 18, 2022

Hey @totemcaf
Great idea! Let's implement it

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

No branches or pull requests

2 participants