on master help sign in
added takeWhile and dropWhile to lib/prelude/list.idr
78fb1dbMekeor Melire
lib/prelude/list.idr+8
@@ -88,6 +88,14 @@ drop O xs = xs
88drop (S n) [] = []
88drop (S n) [] = []
89drop (S n) (x::xs) = drop n xs
89drop (S n) (x::xs) = drop n xs
90
90
91+takeWhile : (a -> Bool) -> List a -> List a
92+takeWhile p [] = []
93+takeWhile p (x::xs) = if p x then x :: takeWhile p xs else []
94+
95+dropWhile : (a -> Bool) -> List a -> List a
96+dropWhile p [] = []
97+dropWhile p (x::xs) = if p x then dropWhile p xs else x::xs
98+
91--------------------------------------------------------------------------------
99--------------------------------------------------------------------------------
92-- Misc.
100-- Misc.
93--------------------------------------------------------------------------------
101--------------------------------------------------------------------------------