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

20
LINES

< > BotCompany Repo | #1028570 // ListAndIndex

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

Libraryless. Click here for Pure Java version (22032L/133K).

srecord ListAndIndex<A>(L<A> list, int idx) {
  bool atEnd() { ret idx >= l(list); }
  
  A get() { ret _get(list, idx); }
  int size() { ret l(list); }
  
  toString {
    ret subList(list, 0, idx) + ", then " + subList(list, idx);
  }
  
  ListAndIndex<A> plus(int ofs) { ret ListAndIndex(list, idx+ofs); }
  ListAndIndex<A> minus(int ofs) { ret ListAndIndex(list, idx-ofs); }
  
  L<A> list() { ret list; }
  int index aka idx() { ret idx; }
  
  ListAndIndex<A> mapIdx(IF1_IntToInt f) {
    ret ListAndIndex<A>(list, f.get(idx));
  }
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1028570
Snippet name: ListAndIndex
Eternal ID of this version: #1028570/13
Text MD5: 8f2792b66e1f525f981d30a70a08f166
Transpilation MD5: 615e4fe47a89668bd048f8930867d3b6
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-04-05 21:08:56
Source code size: 558 bytes / 20 lines
Pitched / IR pitched: No / No
Views / Downloads: 177 / 530
Version history: 12 change(s)
Referenced in: [show references]