Last active
March 30, 2021 16:11
-
-
Save johnkil/e753259e8977d5b796d0f8d23eea3cbf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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