Created
November 22, 2022 17:49
-
-
Save NikolaDespotoski/053351713e5b75705d3a0c5d61d89d84 to your computer and use it in GitHub Desktop.
Convert MlKitAnalyzer.Result into kotlin.Result so you can utilize kotlin's Result API
This file contains hidden or 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
/** | |
* Converts [MlKitAnalyzer.Result] into [kotlin.Result] | |
* @param detector Any [Detector] | |
* @returns [kotlin.Result] | |
*/ | |
fun <T> MlKitAnalyzer.Result.toResult(detector: Detector<T>): Result<T> = | |
kotlin.runCatching { | |
val value = getValue(detector) ?: throw getThrowable(detector)!! | |
value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment