Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Refactor Res
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed May 13, 2022
1 parent b22e4b3 commit 36f4c44
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ivy-fp/src/main/java/com/ivy/fp/monad/Res.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ suspend fun <T> tryOp(
}
}

// ------------------ mapError --------------------------------------
suspend infix fun <A, E, T, E2> (suspend (A) -> Res<E, T>).mapError(
errorMapping: suspend (E) -> E2
): suspend (A) -> Res<E2, T> = { a ->
Expand All @@ -52,7 +53,10 @@ suspend infix fun <E, T, E2> (suspend () -> Res<E, T>).mapError(
is Res.Ok<*, T> -> res
}
}
// ------------------ mapError --------------------------------------


// ------------------ mapSuccess --------------------------------------
suspend infix fun <A, E, T, T2> (suspend (A) -> Res<E, T>).mapSuccess(
successMapping: suspend (T) -> T2
): suspend (A) -> Res<E, T2> = { a ->
Expand All @@ -62,7 +66,6 @@ suspend infix fun <A, E, T, T2> (suspend (A) -> Res<E, T>).mapSuccess(
}
}


suspend infix fun <E, T, T2> (suspend () -> Res<E, T>).mapSuccess(
successMapping: suspend (T) -> T2
): suspend () -> Res<E, T2> = {
Expand All @@ -71,3 +74,4 @@ suspend infix fun <E, T, T2> (suspend () -> Res<E, T>).mapSuccess(
is Res.Ok<*, T> -> Res.Ok<E, T2>(successMapping(res.data))
}
}
// ------------------ mapSuccess --------------------------------------

0 comments on commit 36f4c44

Please sign in to comment.