resultCtx<T extends Object, E extends Object> function

Result<T, E> resultCtx<T extends Object, E extends Object>(
  1. T fn(
    1. ResultCtx<T, E>
    ), {
  2. E mapErr(
    1. E
    )?,
})

Implementation

Result<T, E> resultCtx<T extends Object, E extends Object>(
  T Function(ResultCtx<T, E>) fn, {
  E Function(E)? mapErr,
}) {
  try {
    final ctx = ResultCtx<T, E>();
    final ok = fn(ctx);
    return Ok(ok);
  } on E catch (e) {
    final err = mapErr == null ? e : mapErr(e);
    return Err(err);
  }
}