---
# System prepended metadata

title: Untitled

---

We deal with money at Bynk. How would you model a data structure that represents money?


```scala
{ "value": 100, "currency": "USD" }
{ "value": 100, "currency": "SFDfdssdf" }
class CurrencyCode(code: String) extends AnyVal

object CurrencyCode {
 def apply(code: String): Option[CurrencyCode] = {
 ...
 }
}

case class Amount(value: Long, currency: String)

def addAmount(a1: Amount, a2: Amount): Either[String, Amount] = {
    if (a1.currency != a2.currency) {
        Left("currency did not match")
    } else {
        Right(Amount(a1.value + a2.value, a1.currency))
    }
}
```
```go


type Amount struct {
    Value int64
    Currency string
}

func (a Amount) Add(r Amount) (Amount, error) {
if a.currency != r.currency {
return errors.New("currencies did not match")
}

return Amount{value: a.Value + r.Value, currency: a.Currency}
}
```