Skip to content

RillOptionOps<A>

extensionRillOptionOps<A>onRill<Option<A>>

Operations on a Rill of Options.

Properties

unNone extension no setter

Rill<A>getunNone

Filters out None elements and unwraps all Some values.

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

Implementation
dart
Rill<A> get unNone => collect(identity);

unNoneTerminate extension no setter

Rill<A>getunNoneTerminate

Unwraps Some values and terminates the stream at the first None.

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

Implementation
dart
Rill<A> get unNoneTerminate {
  Pull<A, Unit> loop(Pull<Option<A>, Unit> p) {
    return p.uncons.flatMap((hdtl) {
      return hdtl.foldN(
        () => Pull.done,
        (hd, tl) => hd
            .indexWhere((opt) => opt.isEmpty)
            .fold(
              () => Pull.output(hd.map((opt) => opt.get)).append(() => loop(tl)),
              (idx) => idx == 0 ? Pull.done : Pull.output(hd.take(idx).map((opt) => opt.get)),
            ),
      );
    });
  }

  return loop(underlying).rillNoScope;
}