SHARE
TWEET

Untitled

a guest Oct 21st, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class IteratorStream<Item, Quality> extends StreamBase<Item, Quality> {
  2.     var iterator: Iterator<Item>;
  3.  
  4.     public function new(iterator)
  5.         this.iterator = iterator;
  6.  
  7.     override function next():Future<Step<Item, Quality>>
  8.         return switch iterator.hasNext() {
  9.             case true: Link(iterator.next(), this);
  10.             case false: End;
  11.         }
  12.  
  13.     override public function forEach<Safety>(handler:Handler<Item, Safety>) {
  14.         return Future.async(function step(cb:Conclusion<Item, Safety, Quality>->Void)
  15.             switch iterator.hasNext() {
  16.                 case true:
  17.                     handler.apply(iterator.next()).handle(function (s) {
  18.                         switch s {
  19.                             case BackOff:
  20.                                 cb(Halted(this));
  21.                             case Finish:
  22.                                 cb(Halted(this));
  23.                             case Resume:
  24.                                 step(cb);
  25.                             case Clog(e):
  26.                                 cb(Clogged(e, this));
  27.                         }
  28.                     });
  29.                 case false: cb(Depleted);
  30.             }, true);
  31.     }
  32. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top