Skip to content

Commit

Permalink
Add the Count function to the standard library
Browse files Browse the repository at this point in the history
  • Loading branch information
mariari committed Nov 8, 2024
1 parent 4d5b43e commit ecfb567
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Stdlib/Data/List/Base.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ length {A} (list : List A) : Nat :=
suc acc
};

--- 𝒪(𝓃). Find the number of elements in a ;List;. that satisfy a given predicate.
count {A} : (A -> Bool) -> List A -> Nat
| predicate := filter predicate >> length;

--- 𝒪(𝓃). Returns the given ;List; in reverse order.
{-# isabelle-function: {name: "rev"} #-}
reverse {A} (list : List A) : List A :=
Expand Down

0 comments on commit ecfb567

Please sign in to comment.