Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

56
LINES

< > BotCompany Repo | #1035879 // Stages2

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (11046L) is out of date.

// goes well with the stage {} macro (see tok_stages)
srecord Stages2(L<Stages2.Stage> stages) is Steppable, Runnable {
  int iStage;
  Stage stage;
  
  // set this to record timing for each stage
  settable transient FunctionTimings<S> timings;
  
  { stages = new L; }
  
  record noeq Stage(S name, Runnable body) {
    run {
      if (timings != null)
        timings.do(name, body);
      else
        callF(body);
    }
    
    toString { ret or2(name, "Unnamed stage"); }
  }
  
  public bool step() {
    if (iStage >= l(stages)) false;
    var stage = stages.get(iStage++);
    stage.run();
    true;
  }
  
  Stage stage(Stage stage) {
    stages.add(stage);
    ret stage;
  }
  
  Stage stage(S name, Runnable body) {
    ret stage(new Stage(name, body));
  }
  
  run { stepAll(this); }
  
  int indexOfStage(Stage stage) {
    ret stages.indexOf(stage);
  }
  
  void stepUntilStage(Stage stage) {
    int index = indexOfStage(stage);
    while (iStage <= index && step()) {}
  }
  
  L<Stage> completedStages() {
    ret cloneTakeFirst(stages, iStage);
  }
  
  L<Stage> remainingStages() {
    ret cloneDropFirst(stages, iStage);
  }
}

Author comment

Began life as a copy of #1032842

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): mqqgnosmbjvj, wnsclhtenguj

No comments. add comment

Snippet ID: #1035879
Snippet name: Stages2
Eternal ID of this version: #1035879/10
Text MD5: 763817a679dadd0f99a065cd91733094
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-02-12 11:27:34
Source code size: 1208 bytes / 56 lines
Pitched / IR pitched: No / No
Views / Downloads: 172 / 258
Version history: 9 change(s)
Referenced in: #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167)