Created
May 11, 2020 11:44
-
-
Save nilsmagnus/84e6658a166552e14ab669a1b5930bd8 to your computer and use it in GitHub Desktop.
run a block and return result wrapped in an arrow.Either<Throwable,R>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import arrow.core.Either | |
public inline fun <R> catch(block: () -> R): Either<Throwable,R> { | |
return try { | |
Either.right(block()) | |
} catch (e: Throwable) { | |
Either.left(e) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment