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

33
LINES

< > BotCompany Repo | #1006330 // third - get third element from a list

JavaX fragment (include)

1  
static <A> A third(L<A> l) {
2  
  return _get(l, 2);
3  
}
4  
5  
static <A> A third(Iterable<A> l) {
6  
  if (l == null) null;
7  
  Iterator<A> it = iterator(l);
8  
  repeat 2 {
9  
    if (!it.hasNext()) null;
10  
    it.next();
11  
  }
12  
  ret it.hasNext() ? it.next() : null;
13  
}
14  
15  
ifclass Producer
16  
static <A> A third(Producer<A> p) {
17  
  if (p == null) null;
18  
  repeat 2 {
19  
    if (p.next() == null) null;
20  
  }
21  
  ret p.next();
22  
}
23  
endif
24  
25  
static <A> A third(A[] bla) {
26  
  ret bla == null || bla.length <= 2 ? null : bla[2];
27  
}
28  
29  
ifclass T3
30  
static <A, B, C> C third(T3<A, B, C> t) {
31  
  ret t == null ? null : t.c;
32  
}
33  
endif

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1006330
Snippet name: third - get third element from a list
Eternal ID of this version: #1006330/6
Text MD5: 968646c1e365ac398be34bbcce76b550
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-03-31 19:15:54
Source code size: 606 bytes / 33 lines
Pitched / IR pitched: No / No
Views / Downloads: 669 / 708
Version history: 5 change(s)
Referenced in: [show references]