-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(common): modify access rights
- Loading branch information
Showing
10 changed files
with
230 additions
and
233 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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.liftric.base | ||
|
||
class Result<out T> constructor(val value: Any?) { | ||
val isSuccess: Boolean get() = value !is Failure | ||
val isFailure: Boolean get() = value is Failure | ||
|
||
companion object { | ||
fun <T> success(value: T): Result<T> = Result(value) | ||
fun <T> failure(exception: Throwable): Result<T> = Result(Failure(exception)) | ||
} | ||
|
||
class Failure(val exception: Throwable) { | ||
override fun equals(other: Any?): Boolean = other is Failure && exception == other.exception | ||
override fun hashCode(): Int = exception.hashCode() | ||
override fun toString(): String = "Failure($exception)" | ||
} | ||
|
||
fun getOrNull(): T? = | ||
when { | ||
isFailure -> null | ||
else -> value as T | ||
} | ||
|
||
fun exceptionOrNull(): Throwable? = | ||
when (value) { | ||
is Failure -> value.exception | ||
else -> null | ||
} | ||
} |
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
Oops, something went wrong.