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

17
LINES

< > BotCompany Repo | #1027607 // rWatcher_noRunFirstTime - wrap a Runnable & only run it if a value has changed

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

Libraryless. Click here for Pure Java version (2209L/14K).

static <A> Runnable rWatcher_noRunFirstTime(IF0<A> calc, Runnable r) {
  ret rWatcher_noRunFirstTime(calc, runnableToIVF1(r));
}

static <A> Runnable rWatcher_noRunFirstTime(IF0<A> calc, IVF1<A> r) {
  ret new Runnable {
    A value = callF(calc);
    
    run {
      A newValue = callF(calc);
      if (neq(value, newValue)) {
        value = newValue;
        callF(r, value);
      }
    }
  };
}

Author comment

Began life as a copy of #1024376

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1027607
Snippet name: rWatcher_noRunFirstTime - wrap a Runnable & only run it if a value has changed
Eternal ID of this version: #1027607/2
Text MD5: a4abbf6ee366fa5dc6cab141046038ee
Transpilation MD5: 716f7219dfb3f7c21b7ae64dfcd30655
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-03-25 20:28:31
Source code size: 416 bytes / 17 lines
Pitched / IR pitched: No / No
Views / Downloads: 127 / 192
Version history: 1 change(s)
Referenced in: [show references]