Skip to content

Instantly share code, notes, and snippets.

@johnkil
Last active March 30, 2021 16:11
Show Gist options
  • Save johnkil/e753259e8977d5b796d0f8d23eea3cbf to your computer and use it in GitHub Desktop.
Save johnkil/e753259e8977d5b796d0f8d23eea3cbf to your computer and use it in GitHub Desktop.
inline class CurrencyCode private constructor(private val isoCode: String) {
override fun toString(): String = isoCode
companion object {
fun from(isoCode: String): CurrencyCode {
require(isoCode.matches("^[A-Za-z]{3}$".toRegex())) {
"Invalid ISO 4217 currency code format: $isoCode"
}
return CurrencyCode(isoCode.toUpperCase(Locale.ROOT).intern())
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment