Skip to content

RethrowOps<A>

extensionRethrowOps<A>onRill<Either<Object,A>>

Operations on a Rill of Either values.

Properties

rethrowError extension no setter

Rill<A>getrethrowError

Unwraps Right values and raises the first Left value as an error.

Elements before the first Left are emitted normally; everything after is discarded once the error is raised.

Available on Rill<O>, provided by the RethrowOps<A> extension

Implementation
dart
Rill<A> get rethrowError {
  return chunks().flatMap((c) {
    Option<Object> errOpt = none();
    final size = c.size;
    var i = 0;

    final bldr = <A>[];

    while (i < size && errOpt.isEmpty) {
      c[i].fold(
        (ex) => errOpt = Some(ex),
        (o) {
          bldr.add(o);
          i++;
        },
      );
    }

    final chunk = Chunk.fromList(bldr);

    return Rill.chunk(chunk).append(
      () => errOpt.fold(
        () => Rill.empty(),
        (err) => Rill.raiseError(err),
      ),
    );
  });
}