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

45
LINES

< > BotCompany Repo | #1005162 - second function (get second element)

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

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

1  
static <A> A second(L<A> l) {
2  
  return get(l, 1);
3  
}
4  
5  
static <A> A second(Iterable<A> l) {
6  
  if (l == null) null;
7  
  Iterator<A> it = iterator(l);
8  
  if (!it.hasNext()) null;
9  
  it.next();
10  
  ret it.hasNext() ? it.next() : null;
11  
}
12  
13  
static <A> A second(A[] bla) {
14  
  ret bla == null || bla.length <= 1 ? null : bla[1];
15  
}
16  
17  
ifclass Pair
18  
static <A, B> B second(Pair<A, B> p) {
19  
  ret p == null ? null : p.b;
20  
}
21  
endif
22  
23  
ifclass T3
24  
static <A, B, C> B second(T3<A, B, C> t) {
25  
  ret t == null ? null : t.b;
26  
}
27  
endif
28  
29  
ifclass Producer
30  
static <A> A second(Producer<A> p) {
31  
  if (p == null) null;
32  
  if (p.next() == null) null;
33  
  ret p.next();
34  
}
35  
endif
36  
37  
static char second(S s) {
38  
  ret charAt(s, 1);
39  
}
40  
41  
ifclass Either
42  
static <A, B> B second(Either<A, B> e) {
43  
  ret e == null ? null : e.bOpt();
44  
}
45  
endif

Author comment

Began life as a copy of #1000628

download  show line numbers  debug dex  old transpilations   

Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1005162
Snippet name: second function (get second element)
Eternal ID of this version: #1005162/10
Text MD5: 6d9e8f71bc4b0ee79314bdabb8eacb2e
Transpilation MD5: 150550eafbfbd9b5fca7fe506fdf8ee3
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-05-23 17:16:58
Source code size: 822 bytes / 45 lines
Pitched / IR pitched: No / No
Views / Downloads: 475 / 521
Version history: 9 change(s)
Referenced in: [show references]