Skip to content

Commit f90a657

Browse files
committed
Use filter for find definition
We can utilize the new head function to better compose this
1 parent a567cf1 commit f90a657

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

Stdlib/Data/List/Base.juvix

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,8 @@ isElement {A} (eq : A -> A -> Bool) (elem : A) : (list : List A) -> Bool
1818
--- 𝒪(𝓃). Returns the leftmost element of the list satisfying the predicate or
1919
--- nothing if there is no such element.
2020
{-# specialize: [1] #-}
21-
find {A} (predicate : A -> Bool) : (list : List A) -> Maybe A
22-
| nil := nothing
23-
| (x :: xs) :=
24-
if
25-
| predicate x := just x
26-
| else := find predicate xs;
21+
find {A} (predicate : A -> Bool) : (list : List A) -> Maybe A :=
22+
filter predicate >> headMaybe;
2723

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

0 commit comments

Comments
 (0)