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

36
LINES

< > BotCompany Repo | #1000798 // dropFirst function (drop first elements of array or chars of string - synonym of "drop")

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

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

static S[] dropFirst(int n, S[] a) {
  return drop(n, a);
}

static S[] dropFirst(S[] a) {
  return drop(1, a);
}

static O[] dropFirst(O[] a) {
  return drop(1, a);
}

static <A> L<A> dropFirst(L<A> l) {
  return dropFirst(1, l);
}

static <A> L<A> dropFirst(int n, Iterable<A> i) { ret dropFirst(n, toList(i)); }
static <A> L<A> dropFirst(Iterable<A> i) { ret dropFirst(toList(i)); }

static <A> L<A> dropFirst(int n, L<A> l) {
  ret n <= 0 ? l : new ArrayList(l.subList(Math.min(n, l.size()), l.size()));
}

static <A> L<A> dropFirst(L<A> l, int n) {
  ret dropFirst(n, l);
}

static S dropFirst(int n, S s) { ret substring(s, n); }
static S dropFirst(S s, int n) { ret substring(s, n); }
static S dropFirst(S s) { ret substring(s, 1); }

ifclass Chain
static <A> Chain<A> dropFirst(Chain<A> c) {
  ret c?.next;
}
endif

Author comment

Began life as a copy of #1000705

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1000798
Snippet name: dropFirst function (drop first elements of array or chars of string - synonym of "drop")
Eternal ID of this version: #1000798/9
Text MD5: 30ca02e7874999c51cc740aec90bf1e4
Transpilation MD5: 18c7f72eace428e44ffaf59b2888865f
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-02-25 21:57:32
Source code size: 857 bytes / 36 lines
Pitched / IR pitched: No / No
Views / Downloads: 916 / 1202
Version history: 8 change(s)
Referenced in: #1002427 - Accellerating 629 (SPIKE)
#1003099 - takeLast function (take last n elements of a list or characters of a string)
#1005094 - dropFirstAndLast function (drop n first and n last elements of list or string, makes new ArrayList)
#1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1036541 - cloneDropFirst function - dropFirst + always return new list
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)