Last active
March 9, 2021 07:22
-
-
Save nomisRev/8f10a30f4f087d24a006a0b6093b4c8f to your computer and use it in GitHub Desktop.
EitherEffect require syntax
This file contains hidden or 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 | |
| import arrow.core.computations.EitherEffect | |
| import arrow.core.computations.either | |
| suspend fun <E> EitherEffect<E, *>.require(test: Boolean, fail: () -> E): Unit = | |
| if (test) Unit | |
| else Either.Left(fail()).bind() | |
| suspend fun <E> EitherEffect<E, *>.error(error: E): Unit = | |
| Either.Left(error).bind() | |
| object CustomError | |
| suspend fun main() { | |
| val x: Either<CustomError, Long> = either { | |
| require(10 > 1) { CustomError } | |
| error(CustomError) | |
| 1L | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment