on master help sign in
Merge pull request #24 from MekeorMelire/master
9e399b2Edwin Brady
lib/prelude/complex.idr+5
@@ -1,3 +1,8 @@
1+{-
2+ © 2012 Copyright Mekeor Melire
3+-}
4+
5+
1module prelude.complex
6module prelude.complex
2
7
3import builtins
8import builtins
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--------------------------------------------------------------------------------
lib/prelude/strings.idr+8
@@ -62,3 +62,11 @@ ltrim xs with (strM xs)
62trim : String -> String
62trim : String -> String
63trim xs = ltrim (reverse (ltrim (reverse xs)))
63trim xs = ltrim (reverse (ltrim (reverse xs)))
64
64
65+words' : List Char -> List (List Char)
66+words' s = case dropWhile isSpace s of
67+ [] => []
68+ s' => let (w, s'') = break isSpace s'
69+ in w :: words' s''
70+
71+words : String -> List String
72+words s = map pack $ words' $ unpack s