ZIO<R, E, A>.Do constructor
ZIO<R, E, A>.Do (
- DoFunction<
R, E, A> f
Do notation for ZIO. You can use async/await to write your code in a imperative style.
ZIO.Do(($, env) async {
final a = await $(ZIO.succeed(1));
final b = await $(ZIO.succeed(2));
return a + b;
});
Implementation
// ignore: non_constant_identifier_names
factory ZIO.Do(DoFunction<R, E, A> f) => ZIO.from((ctx) => fromThrowable(
() => f(DoContext(ctx), ctx.env),
onError: (err, stack) {
if (err is Cause<E>) {
return err;
}
return Defect(err, stack);
},
));