-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Refactor Kotlin samples of
EmailAddress.Companion.fromString
Replaces `runCatching` function by `try catch` blocks in these samples. Ref: #635
- Loading branch information
Showing
1 changed file
with
10 additions
and
4 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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") | ||
|