Skip to content

Instantly share code, notes, and snippets.

@NikolaDespotoski
Created November 22, 2022 17:49
Show Gist options
  • Select an option

  • Save NikolaDespotoski/053351713e5b75705d3a0c5d61d89d84 to your computer and use it in GitHub Desktop.

Select an option

Save NikolaDespotoski/053351713e5b75705d3a0c5d61d89d84 to your computer and use it in GitHub Desktop.

Revisions

  1. NikolaDespotoski created this gist Nov 22, 2022.
    10 changes: 10 additions & 0 deletions MlKitAnalyzerKtx.kt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    /**
    * 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
    }