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


< > BotCompany Repo | #1007549 - takeFirst function (take first n elements of a list; or characters of a string)

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

Transpiled version (3967L) is out of date.

static <A> L<A> takeFirst(L<A> l, int n) {
  ret l(l) <= n ? l : newSubListOrSame(l, 0, n);

static <A> L<A> takeFirst(int n, L<A> l) {
  ret takeFirst(l, n);

static S takeFirst(int n, S s) { ret substring(s, 0, n); }
static S takeFirst(S s, int n) { ret substring(s, 0, n); }

static CharSequence takeFirst(int n, CharSequence s) { ret subCharSequence(s, 0, n); }

static <A> L<A> takeFirst(int n, Iterator<A> it) {
  if (it == null) null;
  new L l;
  repeat n { if (it.hasNext()) l.add(; else break; }
  ret l;

static <A> L<A> takeFirst(int n, Iterable<A> i) {
  if (i == null) null;
  ret i == null ?: takeFirst(n, i.iterator());

static <A> L<A> takeFirst(int n, ItIt<A> i) {
  ret takeFirst(n, (Iterator<A>) i);

static int[] takeFirst(int n, int[] a) { ret takeFirstOfIntArray(n, a); }

static short[] takeFirst(int n, short[] a) { ret takeFirstOfShortArray(n, a); }

static byte[] takeFirst(int n, byte[] a) { ret takeFirstOfByteArray(n, a); }
static byte[] takeFirst(byte[] a, int n) { ret takeFirstOfByteArray(n, a); }

static double[] takeFirst(int n, double[] a) { ret takeFirstOfDoubleArray(n, a); }
static double[] takeFirst(double[] a, int n) { ret takeFirstOfDoubleArray(n, a); }

Author comment

Began life as a copy of #1003099

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1007549
Snippet name: takeFirst function (take first n elements of a list; or characters of a string)
Eternal ID of this version: #1007549/21
Text MD5: 5c156d4c77004e462c01c01b760afdcf
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-17 21:30:21
Source code size: 1254 bytes / 38 lines
Pitched / IR pitched: No / No
Views / Downloads: 547 / 717
Version history: 20 change(s)
Referenced in: [show references]