Skip to content

Commit

Permalink
Add conversion from UCT to UCE with mapping block (#41)
Browse files Browse the repository at this point in the history
* Add conversion from UCT to UCE with mapping block

* Feedback and suppress no usage
  • Loading branch information
Jawnnypoo committed Jan 10, 2024
1 parent 347f410 commit b5ce0a0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lce/src/main/java/com/laimiux/lce/Convert.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("unused")

package com.laimiux.lce

/**
Expand Down Expand Up @@ -258,6 +260,18 @@ fun <C> UCT<C>.asCE(): CE<C, Throwable>? {
)
}

/**
* Converts [UCT] to a [UCE] by [mapping][map] the error state to [E].
*/
fun <C, E> UCT<C>.asUCE(map: (throwable: Throwable) -> E): UCE<C, E> {
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].
*/
Expand Down

0 comments on commit b5ce0a0

Please sign in to comment.