on master help sign in
added takeWhile and dropWhile to lib/prelude/list.idr
commit78fb1db2378a7d3b69a86300d4a65ce90dc49a36 authorMekeor Melire <mekeor@ymail.com> dateMon 9 Apr 2012, 17:54 (15 years ago) parent400f858
1 file changed+8
lib/prelude/list.idr+8
lib/prelude/list.idr+8
@@ -88,6 +88,14 @@ drop O xs = xs
8888drop (S n) [] = []
8989drop (S n) (x::xs) = drop n xs
9090
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+
9199--------------------------------------------------------------------------------
92100-- Misc.
93101--------------------------------------------------------------------------------