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

21
LINES

< > BotCompany Repo | #1001038 - last function (get last element of list or last character in string)

JavaX fragment (include)

static <A> A last(L<A> l) {
  return empty(l) ? null : l.get(l.size()-1);
}

static char last(S s) {
  ret empty(s) ? '#' : s.charAt(l(s)-1);
}

static int last(int[] a) {
  ret l(a) != 0 ? a[l(a)-1] : 0;
}

static <A> A last(A[] a) {
  ret l(a) != 0 ? a[l(a)-1] : null;
}

static <A> A last(Iterator<A> it) {
  A a = null;
  while ping (it.hasNext()) a = it.next();
  ret a;
}

download  show line numbers  debug dex   

Travelled to 11 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, tslmcundralx, tvejysmllsmz, whxojlpjdney

No comments. add comment

Snippet ID: #1001038
Snippet name: last function (get last element of list or last character in string)
Eternal ID of this version: #1001038/8
Text MD5: 45b1db11452b112933d2e67e8d9bdb4a
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-01-11 15:42:43
Source code size: 397 bytes / 21 lines
Pitched / IR pitched: No / No
Views / Downloads: 410 / 2950
Version history: 7 change(s)
Referenced in: [show references]