Skip to content

Commit efaa0d2

Browse files
committed
Add the Count function to the standard library
1 parent a4afe0f commit efaa0d2

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Stdlib/Data/List/Base.juvix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ length {A} (list : List A) : Nat :=
7575
suc acc
7676
};
7777

78+
--- 𝒪(𝓃). Find the number of elements in a ;List;. that satisfy a given predicate.
79+
count {A} : (A -> Bool) -> List A -> Nat
80+
| predicate := filter predicate >> length;
81+
7882
--- 𝒪(𝓃). Returns the given ;List; in reverse order.
7983
{-# isabelle-function: {name: "rev"} #-}
8084
reverse {A} (list : List A) : List A :=

0 commit comments

Comments
 (0)