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

65
LINES

< > BotCompany Repo | #1032804 // OpsOnVars [dev.]

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

Libraryless. Click here for Pure Java version (4384L/25K).

sclass OpsOnVars {
  MapSO vars = syncTreeMap();
  
  sclass NotRunYet {}
  static new NotRunYet notRunYet;
  
  *(O... _) {
    addParamsToMap_inPlace(vars, _);
  }
  
  O getVar aka get(S var) { ret vars.get(var); }
  void setVar aka set(S var, O value) { if (var != null) vars.put(var, value); }
  
  record SetVar(S var, O value) is Runnable {
    run { setVar(var, value); }
  }
  
  // SINGLE-OPS (one input variable, one output variable)
  
  macro singleOpCtors {  
    *() {}
    *(S *inVar, S *outVar) {}
  }
  
  abstract noeq record SingleOp(S inVar, S outVar) is Runnable {
    transient O value = notRunYet;
    
    abstract O perform(O arg);
    
    run { get(); }
    
    O get() {
      value = perform(getVar(inVar));
      setVar(outVar, value);
      ret value;
    }
  }
  
  // MULTI-OPS (multiple input variables, one output variable)
  
  abstract noeq record MultiOp(LS inVars, S outVar) is Runnable {
    transient O value = notRunYet;
    
    abstract O perform(L values);
    
    *(S... vars) {
      outVar = last(vars);
      inVars = asListMinusLast(vars);
    }
    
    run { get(); }
    
    O get() {
      value = perform(map getVar(inVars);
      setVar(outVar, value);
      ret value;
    }
  }
  
  macro multiOpCtors {  
    *() {}
    *(LS *inVars, S *outVar) {}
    *(S... vars) { super(vars); }
  }
}

Author comment

Began life as a copy of #1032649

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1032804
Snippet name: OpsOnVars [dev.]
Eternal ID of this version: #1032804/2
Text MD5: 2ca1247fa9b87ad013a9d6401d8eeb29
Transpilation MD5: 3117c881b5f1a0b5cf1abbe4a6d5d544
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-06 08:13:49
Source code size: 1414 bytes / 65 lines
Pitched / IR pitched: No / No
Views / Downloads: 69 / 108
Version history: 1 change(s)
Referenced in: [show references]