mirror of
https://github.com/bitwarden/android.git
synced 2026-06-07 06:49:07 -05:00
Add flatMap for Result type (#51)
This commit is contained in:
committed by
Álison Fernandes
parent
70ec944469
commit
36942ab296
@@ -0,0 +1,10 @@
|
||||
package com.x8bit.bitwarden.data.platform.util
|
||||
|
||||
/**
|
||||
* Flat maps a successful [Result] with the given [transform] to another [Result], and leaves
|
||||
* failures untouched.
|
||||
*/
|
||||
inline fun <T, R> Result<T>.flatMap(transform: (T) -> Result<R>): Result<R> =
|
||||
this.exceptionOrNull()
|
||||
?.let { Result.failure(it) }
|
||||
?: transform(this.getOrThrow())
|
||||
Reference in New Issue
Block a user