Skip to content

Commit

Permalink
♻️ Refactor Kotlin samples of EmailAddress.Companion.fromString
Browse files Browse the repository at this point in the history
Replaces `runCatching` function by `try catch` blocks in these samples.

Ref: #635
  • Loading branch information
LVMVRQUXL committed Apr 18, 2024
1 parent 47e3425 commit 97df006
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,26 @@ internal object EmailAddressCompanionKotlinSample {
@Suppress("FunctionName")
fun fromString_Any() {
val value: Any = "[email protected]"
val result: Result<EmailAddress> = kotlin.runCatching {
val isSuccess: Boolean = try {
EmailAddress.fromString(value) // TABS: 1
true // TABS: 1
} catch (exception: IllegalArgumentException) {
false // TABS: 1
}
println(result.isSuccess) // true
println(isSuccess) // true
} // END

@Suppress("FunctionName")
fun fromString_Any_Any() {
val value: Any = "[email protected]"
val pattern: Any = "^[a-z]+@[a-z]+\\.[a-z]+\$"
val result: Result<EmailAddress> = kotlin.runCatching {
val isSuccess: Boolean = try {
EmailAddress.fromString(value, pattern) // TABS: 1
true // TABS: 1
} catch (exception: IllegalArgumentException) {
false // TABS: 1
}
println(result.isSuccess) // true
println(isSuccess) // true
} // END

@Suppress("FunctionName")
Expand Down

0 comments on commit 97df006

Please sign in to comment.