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.

1  
// goes well with the stage {} macro (see tok_stages)
2  
srecord Stages2(L<Stages2.Stage> stages) is Steppable, Runnable {
3  
  int iStage;
4  
  Stage stage;
5  
  
6  
  // set this to record timing for each stage
7  
  settable transient FunctionTimings<S> timings;
8  
  
9  
  { stages = new L; }
10  
  
11  
  record noeq Stage(S name, Runnable body) {
12  
    run {
13  
      if (timings != null)
14  
        timings.do(name, body);
15  
      else
16  
        callF(body);
17  
    }
18  
    
19  
    toString { ret or2(name, "Unnamed stage"); }
20  
  }
21  
  
22  
  public bool step() {
23  
    if (iStage >= l(stages)) false;
24  
    var stage = stages.get(iStage++);
25  
    stage.run();
26  
    true;
27  
  }
28  
  
29  
  Stage stage(Stage stage) {
30  
    stages.add(stage);
31  
    ret stage;
32  
  }
33  
  
34  
  Stage stage(S name, Runnable body) {
35  
    ret stage(new Stage(name, body));
36  
  }
37  
  
38  
  run { stepAll(this); }
39  
  
40  
  int indexOfStage(Stage stage) {
41  
    ret stages.indexOf(stage);
42  
  }
43  
  
44  
  void stepUntilStage(Stage stage) {
45  
    int index = indexOfStage(stage);
46  
    while (iStage <= index && step()) {}
47  
  }
48  
  
49  
  L<Stage> completedStages() {
50  
    ret cloneTakeFirst(stages, iStage);
51  
  }
52  
  
53  
  L<Stage> remainingStages() {
54  
    ret cloneDropFirst(stages, iStage);
55  
  }
56  
}

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: 109 / 176
Version history: 9 change(s)
Referenced in: [show references]