Skip to content

Commit

Permalink
add count stdlib method
Browse files Browse the repository at this point in the history
  • Loading branch information
simvux committed Dec 2, 2024
1 parent bc45e20 commit cd79719
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions luminapath/std/list/lib.lm
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ pub fn any f list as fn(a -> bool), List a -> bool =
else any #f right
| Nil -> false

// Counts the elements which yield true from `f elem`
pub fn count f list as fn(a -> bool), List a -> uint =
fold #(\acc elem -> if f elem then acc + 1 else acc) 0 list

pub fn from_range range f as (uint, uint), fn(uint -> a) -> List a =
Slice (vec:to_slice (vec:from_range range #f))

Expand Down

0 comments on commit cd79719

Please sign in to comment.