diff --git a/lce/src/main/java/com/laimiux/lce/Convert.kt b/lce/src/main/java/com/laimiux/lce/Convert.kt index 5f70248..aef3992 100644 --- a/lce/src/main/java/com/laimiux/lce/Convert.kt +++ b/lce/src/main/java/com/laimiux/lce/Convert.kt @@ -1,3 +1,5 @@ +@file:Suppress("unused") + package com.laimiux.lce /** @@ -258,6 +260,18 @@ fun UCT.asCE(): CE? { ) } +/** + * Converts [UCT] to a [UCE] by [mapping][map] the error state to [E]. + */ +fun UCT.asUCE(map: (throwable: Throwable) -> E): UCE { + return foldTypes( + onLoading = { it }, + onContent = { it }, + onError = { UCE.error(map(it.value)) } + ) +} + + /** * Converts [UCT] to a [CE] by [mapping][map] the loading state to [CE]. */