Skip to content

Instantly share code, notes, and snippets.

@NikolaDespotoski
Created November 22, 2022 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NikolaDespotoski/053351713e5b75705d3a0c5d61d89d84 to your computer and use it in GitHub Desktop.
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
/**
* 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