Skip to content

Commit

Permalink
Use filter for find definition
Browse files Browse the repository at this point in the history
We can utilize the new head function to better compose this
  • Loading branch information
mariari committed Nov 7, 2024
1 parent a567cf1 commit f90a657
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions Stdlib/Data/List/Base.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@ isElement {A} (eq : A -> A -> Bool) (elem : A) : (list : List A) -> Bool
--- 𝒪(𝓃). Returns the leftmost element of the list satisfying the predicate or
--- nothing if there is no such element.
{-# specialize: [1] #-}
find {A} (predicate : A -> Bool) : (list : List A) -> Maybe A
| nil := nothing
| (x :: xs) :=
if
| predicate x := just x
| else := find predicate xs;
find {A} (predicate : A -> Bool) : (list : List A) -> Maybe A :=
filter predicate >> headMaybe;

syntax iterator listRfor {init := 1; range := 1};

Expand Down

0 comments on commit f90a657

Please sign in to comment.