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

32
LINES

< > BotCompany Repo | #1007610 // popFirst - remove & return first element(s) of collection

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

Libraryless. Click here for Pure Java version (4036L/23K).

static <A> A popFirst(L<A> l) {
  if (empty(l)) null;
  A a = first(l);
  l.remove(0);
  ret a;
}

static <A> A popFirst(Cl<A> l) {
  if (empty(l)) null;
  A a = first(l);
  l.remove(a);
  ret a;
}

static <A, B> Pair<A, B> popFirst(Map<A, B> map) {
  if (map == null) null;
  var it = map.entrySet().iterator();
  if (!it.hasNext()) null;
  var p = mapEntryToPair(it.next());
  it.remove();
  ret p;
}

static <A> L<A> popFirst(int n, L<A> l) {
  L<A> part = cloneSubList(l, 0, n);
  removeSubList(l, 0, n);
  ret part;
}

static <A> AppendableChain<A> popFirst(AppendableChain<A> a) {
  ret a?.popFirst();
}

Author comment

Began life as a copy of #1002780

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1007610
Snippet name: popFirst - remove & return first element(s) of collection
Eternal ID of this version: #1007610/8
Text MD5: c46ad9d62a7a95d792ade67c1462b59f
Transpilation MD5: 24fc6ad9c15661747663a4d9c967e2c2
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-11 15:07:28
Source code size: 640 bytes / 32 lines
Pitched / IR pitched: No / No
Views / Downloads: 698 / 791
Version history: 7 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1013249 - removeFirst - remove first element of list (or multiple)
#1017117 - syncPopFirst - remove & return first element of list - synchronized
#1025776 - popFirst_ping - popFirst + ping