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

32
LINES

< > BotCompany Repo | #1002310 // subList function - use instead of List.subList

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

Libraryless. Click here for Pure Java version (2971L/17K).

static <A> L<A> subList(L<A> l, int startIndex) {
  ret subList(l, startIndex, l(l));
}

static <A> L<A> subList(int startIndex, L<A> l) {
  ret subList(l, startIndex);
}

static <A> L<A> subList(int startIndex, int endIndex, L<A> l) {
  ret subList(l, startIndex, endIndex);
}

static <A> L<A> subList(L<A> l, int startIndex, int endIndex) {
  if (l == null) null;
  int n = l(l);
  startIndex = Math.max(0, startIndex);
  endIndex = Math.min(n, endIndex);
  if (startIndex > endIndex) ret ll();
  if (startIndex == 0 && endIndex == n) ret l;
  ifdef OurSubLists
    ret ourSubList_noRangeCheck(l, startIndex, endIndex);
  endifdef
  ifndef OurSubLists
    ret l.subList(startIndex, endIndex);
  endifndef
}

ifclass IntRange
static <A> L<A> subList(L<A> l, IntRange r) {
  ret subList(l, r.start, r.end);
}
endif

Author comment

Began life as a copy of #1001911

download  show line numbers  debug dex  old transpilations   

Travelled to 17 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, podlckwnjdmb, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1002310
Snippet name: subList function - use instead of List.subList
Eternal ID of this version: #1002310/9
Text MD5: 561528862a976b860c0a1ac7f8d48688
Transpilation MD5: dd1ab59fd583a71fbca9b917a63ae519
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-07-24 02:46:12
Source code size: 845 bytes / 32 lines
Pitched / IR pitched: No / No
Views / Downloads: 1037 / 4406
Version history: 8 change(s)
Referenced in: #1002427 - Accellerating 629 (SPIKE)
#1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1019581 - newSubListOrSame - return cloned subList or original list if full range
#1029829 - subListOrFull - return full list when range is null
#1034970 - cyclicSubList function - see cyclicGet
#1035286 - subListContains
#3000382 - Answer for ferdie (>> t = 1, f = 0)