Created
November 28, 2022 05:55
-
-
Save SandroMaglione/9c9410fb92c5e61a897507e043d534e3 to your computer and use it in GitHub Desktop.
Run side effects in a chain of IOEither using fpdart
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
extension IOExtension<L, R> on IOEither<L, R> { | |
IOEither<L, R> runSideEffect({ | |
final void Function(L l)? onLeft, | |
final void Function(R r)? onRight, | |
}) => | |
chainFirst( | |
(r) => IOEither<L, void>.fromIO( | |
IO(() => onRight?.call(r)), | |
), | |
) | |
.swap() | |
.chainFirst( | |
(r) => IOEither<R, void>.fromIO( | |
IO(() => onLeft?.call(r)), | |
), | |
) | |
.swap(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment