Reconcile the DecCoin and DecCoins APIs with the Coin and Coins APIs for consistency.
e.g.
What did you have in mind? like testing through an interface? golang is kinda inhibiting for actually combining these two types unfortunately
Yeah I wish we could keep it DRY as possible, but I mean just making sure the APIs are the same (e.g. plus doesn't make sure zero coins are removed).
How about defining these common interfaces?
type Coin interface {
SameDenomAs(Coin) bool
Zero() bool
GTE(Coin) bool
LT(Coin) bool
Equal(Coin) bool
Plus(Coin) Coin
Minus(Coin) Coin
Positive() bool
Negative() bool
String() string
}
type CoinSet interface {
Valid() bool
Plus(CoinSet) Coin
Minus(CoinSet) Coin
SafeMinus(CoinSet) Coin
AllGT(CoinSet) bool
AllGTE(CoinSet) bool
AllLTE(CoinSet) bool
Zero() bool
Equal(CoinSet) bool
Empty() bool
AllPositive() bool
AllNotNegative() bool
AnyNegative() bool
Sort() CoinSet
String() string
}
Note that I have removed the Is prefix from all types - IMHO it does not add any value to the methods names.
We might need an Amount interface to allow Int/Dec comparisons
Most helpful comment
How about defining these common interfaces?
Note that I have removed the
Isprefix from all types - IMHO it does not add any value to the methods names.