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

94
LINES

< > BotCompany Repo | #1000628 // first function

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

Transpiled version (9916L) is out of date.

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) { ret empty(l) ? null : l[0]; }
58  
static Double first(double[] l) { ret empty(l) ? null : l[0]; }
59  
60  
ifclass IntBuffer
61  
static int first(IntBuffer buf) {
62  
  ret buf.get(0);
63  
}
64  
endif
65  
66  
ifclass ByteBuffer
67  
static byte first(ByteBuffer buf) {
68  
  ret buf.get(0);
69  
}
70  
endif
71  
72  
static <A> A first(A[] l, IF1<A, Bool> pred) {
73  
  ret firstThat(l, pred);
74  
}
75  
76  
static <A> A first(Iterable<A> l, IF1<A, Bool> pred) {
77  
  ret firstThat(l, pred);
78  
}
79  
80  
static <A> A lambdaMapLike first(IF1<A, Bool> pred, Iterable<A> l) {
81  
  ret firstThat(pred, l);
82  
}
83  
84  
ifclass AppendableChain
85  
static <A> A first(AppendableChain<A> a) {
86  
  ret a == null ? null : a.element;
87  
}
88  
endif
89  
90  
ifclass IMultiSet
91  
static <A> A first(IMultiSet<A> a) {
92  
  ret a == null ?: first(a.keySet());
93  
}
94  
endif

download  show line numbers  debug dex  old transpilations   

Travelled to 19 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, podlckwnjdmb, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, whxojlpjdney, wnsclhtenguj, 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/23
Text MD5: 41745984bff5cc64ae9297e59889a84d
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-02-12 20:41:08
Source code size: 2040 bytes / 94 lines
Pitched / IR pitched: No / No
Views / Downloads: 1405 / 3157
Version history: 22 change(s)
Referenced in: [show references]