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

80
LINES

< > BotCompany Repo | #1001518 // l function (synonym of length), length of arrays, strings, lists, size of maps

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

Libraryless. Click here for Pure Java version (103L/1K).

static int l(Object[] a) { return a == null ? 0 : a.length; }
static int l(bool[] a) { return a == null ? 0 : a.length; }
static int l(byte[] a) { return a == null ? 0 : a.length; }
static int l(short[] a) { return a == null ? 0 : a.length; }
static int l(long[] a) { return a == null ? 0 : a.length; }
static int l(int[] a) { return a == null ? 0 : a.length; }
static int l(float[] a) { return a == null ? 0 : a.length; }
static int l(double[] a) { return a == null ? 0 : a.length; }
static int l(char[] a) { return a == null ? 0 : a.length; }
static int l(Collection c) { return c == null ? 0 : c.size(); }
ifndef l_noIterators
static int l(Iterator i) { return iteratorCount_int_close(i); } // consumes the iterator && closes it if possible
endifndef
static int l(Map m) { return m == null ? 0 : m.size(); }
static int l(CharSequence s) { return s == null ? 0 : s.length(); }
static long l(File f) { ret f == null ? 0 : f.length(); }

ifdef l_withReflection

static int l(Object o) {
  ret o == null ? 0
    : o instanceof S ? l((S) o)
    : o instanceof Map ? l((Map) o)
    : o instanceof Collection ? l((Collection) o)
    : o instanceof O[] ? l((O[]) o)
    : o instanceof bool[] ? l((bool[]) o)
    : o instanceof byte[] ? l((byte[]) o)
    : o instanceof char[] ? l((char[]) o)
    : o instanceof short[] ? l((short[]) o)
    : o instanceof int[] ? l((int[]) o)
    : o instanceof float[] ? l((float[]) o)
    : o instanceof double[] ? l((double[]) o)
    : o instanceof long[] ? l((long[]) o)
    : (Int) call(o, 'size);
}
endifdef

ifclass IMultiSet
  static int l(IMultiSet ms) { ret ms == null ? 0 : ms.size(); }
endif

ifclass IMultiMap
  static int l(IMultiMap mm) { ret mm == null ? 0 : mm.size(); }
endif

ifclass Lisp
  static int l(Lisp l) { ret l == null ? 0 : l.size(); }
endif

ifclass IntRange
  static int l(IntRange r) { ret r == null ? 0 : r.length(); }
endif

ifclass LongRange
  static long l(LongRange r) { ret r == null ? 0 : r.length(); }
endif

ifclass DoubleRange
  static double l(DoubleRange r) { ret r == null ? 0 : r.length(); }
endif

ifclass IntBuffer
  static int l(IntBuffer b) { ret b == null ? 0 : b.size(); }
endif

ifclass LongBuffer
  static int l(LongBuffer b) { ret b == null ? 0 : b.size(); }
endif

ifclass ShortBuffer
  static int l(ShortBuffer b) { ret b == null ? 0 : b.size(); }
endif

ifclass HalfLongs
  static int l(HalfLongs l) { ret l == null ? 0 : l.size(); }
endif

ifclass IntSize
  static int l(IntSize o) { ret o == null ? 0 : o.size(); }
endif

Author comment

Began life as a copy of #1001516

download  show line numbers  debug dex  old transpilations   

Travelled to 25 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, ekrmjmnbrukm, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lnbujpyubztb, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, onxytkatvevr, podlckwnjdmb, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, whxojlpjdney, wnsclhtenguj, wtqryiryparv, xrpafgyirdlv, yanjaxplzisb

No comments. add comment

Snippet ID: #1001518
Snippet name: l function (synonym of length), length of arrays, strings, lists, size of maps
Eternal ID of this version: #1001518/38
Text MD5: eaab1da476db68d5a8d186486ff77dde
Transpilation MD5: 26c2e3c16acfeec06513409b4620a756
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-02-13 23:12:25
Source code size: 2589 bytes / 80 lines
Pitched / IR pitched: No / No
Views / Downloads: 1341 / 10300
Version history: 37 change(s)
Referenced in: #1002427 - Accellerating 629 (SPIKE)
#1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1031763 - n2_l function
#3000382 - Answer for ferdie (>> t = 1, f = 0)