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

14
LINES

< > BotCompany Repo | #1022066 // nextToLastThat - find next to last element in list that matches a predicate

JavaX fragment (include)

static <A> A nextToLastThat(L<A> l, O pred) {
  int found = 0;
  for (int i = l(l)-1; i >= 0; i--) {
    A a = l.get(i);
    if (checkCondition(pred, a))
      if (++found >= 2)
        ret a;
  }
  null;
}

static <A> A mapLike nextToLastThat(O pred, L<A> l) {
  ret nextToLastThat(l, pred);
}

Author comment

Began life as a copy of #1021565

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1022066
Snippet name: nextToLastThat - find next to last element in list that matches a predicate
Eternal ID of this version: #1022066/1
Text MD5: a64fe43272be8cf5a90c226569b623ed
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-03-06 08:39:35
Source code size: 307 bytes / 14 lines
Pitched / IR pitched: No / No
Views / Downloads: 193 / 236
Referenced in: [show references]