Skip to content

Instantly share code, notes, and snippets.

@SandroMaglione
Created November 28, 2022 05:55
Show Gist options
  • Save SandroMaglione/9c9410fb92c5e61a897507e043d534e3 to your computer and use it in GitHub Desktop.
Save SandroMaglione/9c9410fb92c5e61a897507e043d534e3 to your computer and use it in GitHub Desktop.
Run side effects in a chain of IOEither using fpdart
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