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

21
LINES

< > BotCompany Repo | #1006407 // firstThat - find first element in list that matches a predicate

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

Libraryless. Click here for Pure Java version (3857L/22K).

1  
static <A> A firstThat(Iterable<A> l, IF1<A, Bool> pred) {
2  
  fOr (A a : l)
3  
    if (pred.get(a))
4  
      ret a;
5  
  null;
6  
}
7  
8  
static <A> A firstThat(A[] l, IF1<A, Bool> pred) {
9  
  fOr (A a : l)
10  
    if (pred.get(a))
11  
      ret a;
12  
  null;
13  
}
14  
15  
static <A> A lambdaMapLike firstThat(IF1<A, Bool> pred, Iterable<A> l) {
16  
  ret firstThat(l, pred);
17  
}
18  
19  
static <A> A lambdaMapLike firstThat(IF1<A, Bool> pred, A[] l) {
20  
  ret firstThat(l, pred);
21  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1006407
Snippet name: firstThat - find first element in list that matches a predicate
Eternal ID of this version: #1006407/11
Text MD5: bfefba0caaaf3e5e9334030d483d1af2
Transpilation MD5: 52d0046c62978d42174d1be97302491e
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-10 23:51:31
Source code size: 448 bytes / 21 lines
Pitched / IR pitched: No / No
Views / Downloads: 593 / 679
Version history: 10 change(s)
Referenced in: [show references]