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

23
LINES

< > BotCompany Repo | #1004349 // nfilter - count objects in collection that match a predicate

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

Libraryless. Click here for Pure Java version (1748L/11K).

static <A> int nfilter(Iterable<A> c, IF1<A, Bool> pred) {
  ret nfilter(pred, c);
}

static <A> int nfilter(IF1<A, Bool> pred, Iterable<A> c) {
  int n = 0;
  if (c != null) for (A o : c)
    if (pred.get(o))
      ++n;
  ret n;
}

static int nfilter(Iterable c, O pred) {
  int n = 0;
  if (c != null) for (O o : c)
    if (isTrue(callF(pred, o)))
      ++n;
  ret n;
}

static int nfilter(O pred, Iterable c) {
  ret nfilter(c, pred);
}

Author comment

Began life as a copy of #1003524

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, podlckwnjdmb, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1004349
Snippet name: nfilter - count objects in collection that match a predicate
Eternal ID of this version: #1004349/5
Text MD5: b42fee7ad9490d3ff27836c3d162b64c
Transpilation MD5: 386ed1eea0ed398b584334bcbd3c4786
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-08-13 09:25:29
Source code size: 463 bytes / 23 lines
Pitched / IR pitched: No / No
Views / Downloads: 719 / 720
Version history: 4 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1013472 - countPred - synonym of nfilter - count objects in collection that match a predicate