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

89
LINES

< > BotCompany Repo | #1000628 - first function

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

Libraryless. Click here for Pure Java version (4526L/25K).

1  
ifndef NoGenericFunctions
2  
static O first(O list) {
3  
  ret first((Iterable) list);
4  
}
5  
endifndef
6  
7  
static <A> A first(L<A> list) {
8  
  return empty(list) ? null : list.get(0);
9  
}
10  
11  
static <A> A first(A[] bla) {
12  
  ret bla == null || bla.length == 0 ? null : bla[0];
13  
}
14  
15  
static <A, B> Pair<A, B> first(Map<A, B> map) {
16  
  ret mapEntryToPair(first(entrySet(map)));
17  
}
18  
19  
static <A, B> Pair<A, B> first(MultiMap<A, B> mm) {
20  
  if (mm == null) null;
21  
  var e = first(mm.data.entrySet());
22  
  if (e == null) null;
23  
  ret pair(e.getKey(), first(e.getValue());
24  
}
25  
26  
ifclass IterableIterator
27  
static <A> A first(IterableIterator<A> i) {
28  
  ret first((Iterator<A>) i);
29  
}
30  
endif
31  
32  
static <A> A first(Iterator<A> i) {
33  
  ret i == null || !i.hasNext() ? null : i.next();
34  
}
35  
36  
static <A> A first(Iterable<A> i) {
37  
  if (i == null) ret null;
38  
  Iterator<A> it = i.iterator();
39  
  ret it.hasNext() ? it.next() : null;
40  
}
41  
42  
static Char first(S s) { ret empty(s) ? null : s.charAt(0); }
43  
static Char first(CharSequence s) { ret empty(s) ? null : s.charAt(0); }
44  
45  
ifclass Pair
46  
static <A, B> A first(Pair<A, B> p) {
47  
  ret p == null ? null : p.a;
48  
}
49  
endif
50  
51  
ifclass T3
52  
static <A, B, C> A first(T3<A, B, C> t) {
53  
  ret t == null ? null : t.a;
54  
}
55  
endif
56  
57  
static Byte first(byte[] l) { 
58  
  ret empty(l) ? null : l[0];
59  
}
60  
61  
ifclass IntBuffer
62  
static int first(IntBuffer buf) {
63  
  ret buf.get(0);
64  
}
65  
endif
66  
67  
ifclass ByteBuffer
68  
static byte first(ByteBuffer buf) {
69  
  ret buf.get(0);
70  
}
71  
endif
72  
73  
static <A> A first(A[] l, IF1<A, Bool> pred) {
74  
  ret firstThat(l, pred);
75  
}
76  
77  
static <A> A first(Iterable<A> l, IF1<A, Bool> pred) {
78  
  ret firstThat(l, pred);
79  
}
80  
81  
static <A> A lambdaMapLike first(IF1<A, Bool> pred, Iterable<A> l) {
82  
  ret firstThat(pred, l);
83  
}
84  
85  
ifclass AppendableChain
86  
static <A> A first(AppendableChain<A> a) {
87  
  ret a == null ? null : a.element;
88  
}
89  
endif

download  show line numbers  debug dex  old transpilations   

Travelled to 18 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, podlckwnjdmb, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, whxojlpjdney, xrpafgyirdlv

Comments [hide]

ID Author/Program Comment Date
874 #1000610 Edit suggestion:
!636
!629

main {
static Object androidContext;
static String programID;

public static void main(String[] args) throws Exception {
static Object first(Object list) {
return ((List) list).isEmpty() ? null : ((List) list).get(0);
}

}}
2015-08-19 22:48:33  delete 
755 #1000604 (pitcher) 2015-08-19 17:00:56

add comment

Snippet ID: #1000628
Snippet name: first function
Eternal ID of this version: #1000628/21
Text MD5: 5cc497233724dc4ab2d7fe3e2efff430
Transpilation MD5: d4d282beb541df1e639c069e52b3e048
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-23 02:33:11
Source code size: 1874 bytes / 89 lines
Pitched / IR pitched: No / No
Views / Downloads: 1019 / 2667
Version history: 20 change(s)
Referenced in: [show references]