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

26
LINES

< > BotCompany Repo | #1025514 // indicesOf

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

Libraryless. Click here for Pure Java version (2541L/16K).

1  
static <A> L<Int> indicesOf(L<A> l, A a) {
2  
  if (l == null) null;
3  
  
4  
  ifclass IContentsIndexedList
5  
  if (l cast IContentsIndexedList)
6  
    ret intArrayToList(l.indicesOf(a));
7  
  endif
8  
  ifclass IContentsIndexedList2
9  
  if (l cast IContentsIndexedList2)
10  
    ret map(h -> h/HasIndex.idx, l.indicesOf_treeSetOfHasIndex(a));
11  
  endif
12  
  
13  
  new L<Int> x;
14  
  for (int i = 0; i < l(l); i++)
15  
    if (eq(l.get(i), a))
16  
      x.add(i);
17  
  ret x;
18  
}
19  
20  
static <A> L<Int> indicesOf(S s, S x) {
21  
  int i = -1;
22  
  new L<Int> out;
23  
  while ((i = indexOf(s, x, i+1)) >= 0)
24  
    out.add(i);
25  
  ret out;
26  
}

Author comment

Began life as a copy of #1004477

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: #1025514
Snippet name: indicesOf
Eternal ID of this version: #1025514/9
Text MD5: e6526d2d54e8018372fe48c1f0240230
Transpilation MD5: 734553d978168300f9aa15c9ee761dbf
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-07-11 12:52:06
Source code size: 597 bytes / 26 lines
Pitched / IR pitched: No / No
Views / Downloads: 240 / 370
Version history: 8 change(s)
Referenced in: [show references]