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).

1  
static <A> A popFirst(L<A> l) {
2  
  if (empty(l)) null;
3  
  A a = first(l);
4  
  l.remove(0);
5  
  ret a;
6  
}
7  
8  
static <A> A popFirst(Cl<A> l) {
9  
  if (empty(l)) null;
10  
  A a = first(l);
11  
  l.remove(a);
12  
  ret a;
13  
}
14  
15  
static <A, B> Pair<A, B> popFirst(Map<A, B> map) {
16  
  if (map == null) null;
17  
  var it = map.entrySet().iterator();
18  
  if (!it.hasNext()) null;
19  
  var p = mapEntryToPair(it.next());
20  
  it.remove();
21  
  ret p;
22  
}
23  
24  
static <A> L<A> popFirst(int n, L<A> l) {
25  
  L<A> part = cloneSubList(l, 0, n);
26  
  removeSubList(l, 0, n);
27  
  ret part;
28  
}
29  
30  
static <A> AppendableChain<A> popFirst(AppendableChain<A> a) {
31  
  ret a?.popFirst();
32  
}

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: 602 / 645
Version history: 7 change(s)
Referenced in: [show references]