Simplify code

This commit is contained in:
Him188 2019-11-25 14:15:30 +08:00
parent df3838b924
commit 7e55c6f342

View File

@ -90,10 +90,7 @@ inline fun LoginResult.requireSuccess(lazyMessage: (LoginResult) -> String) {
* 检查 [this] [LoginResult.SUCCESS].
* 失败则 [error]
*/
fun LoginResult.requireSuccess() {
if (requireSuccessOrNull() === null)
error("Login failed: $this")
}
fun LoginResult.requireSuccess() = requireSuccess { "Login failed: $this" }
/**
* 检查 [this] [LoginResult.SUCCESS].
@ -101,10 +98,7 @@ fun LoginResult.requireSuccess() {
*
* @return 成功时 [Unit], 失败时 `null`
*/
fun LoginResult.requireSuccessOrNull(): Unit? {
return if (this == SUCCESS) Unit else null
}
fun LoginResult.requireSuccessOrNull(): Unit? = if (this == SUCCESS) Unit else null
/**
* 检查 [this] [LoginResult.SUCCESS].