ifndef NoGenericFunctions
static O first(O list) {
ret first((Iterable) list);
}
endifndef
static A first(L list) {
return empty(list) ? null : list.get(0);
}
static A first(A[] bla) {
ret bla == null || bla.length == 0 ? null : bla[0];
}
static Pair first(Map map) {
ret mapEntryToPair(first(entrySet(map)));
}
static Pair first(MultiMap mm) {
if (mm == null) null;
var e = first(mm.data.entrySet());
if (e == null) null;
ret pair(e.getKey(), first(e.getValue());
}
ifclass IterableIterator
static A first(IterableIterator i) {
ret first((Iterator) i);
}
endif
static A first(Iterator i) {
ret i == null || !i.hasNext() ? null : i.next();
}
static A first(Iterable i) {
if (i == null) ret null;
Iterator it = i.iterator();
ret it.hasNext() ? it.next() : null;
}
static Char first(S s) { ret empty(s) ? null : s.charAt(0); }
static Char first(CharSequence s) { ret empty(s) ? null : s.charAt(0); }
ifclass Pair
static A first(Pair p) {
ret p == null ? null : p.a;
}
endif
ifclass T3
static A first(T3 t) {
ret t == null ? null : t.a;
}
endif
static Byte first(byte[] l) { ret empty(l) ? null : l[0]; }
static Double first(double[] l) { ret empty(l) ? null : l[0]; }
ifclass IntBuffer
static int first(IntBuffer buf) {
ret buf.get(0);
}
endif
ifclass ByteBuffer
static byte first(ByteBuffer buf) {
ret buf.get(0);
}
endif
static A first(A[] l, IF1 pred) {
ret firstThat(l, pred);
}
static A first(Iterable l, IF1 pred) {
ret firstThat(l, pred);
}
static A lambdaMapLike first(IF1 pred, Iterable l) {
ret firstThat(pred, l);
}
ifclass AppendableChain
static A first(AppendableChain a) {
ret a == null ? null : a.element;
}
endif
ifclass IMultiSet
static A first(IMultiSet a) {
ret a == null ?: first(a.keySet());
}
endif