Merge pull request #24 from MekeorMelire/master
slightly extended standard library
commit9e399b2599f87d103aa64f2f5a8c8c759c1fcb86
authorEdwin Brady <edwin.brady@gmail.com>
dateTue 10 Apr 2012, 06:24 (15 years ago)
parenta39197920fc41c
lib/prelude/complex.idr+5
@@ -1,3 +1,8 @@
1+{-
2+ © 2012 Copyright Mekeor Melire
3+-}
4+
5+
16module prelude.complex
27
38import builtins
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--------------------------------------------------------------------------------
lib/prelude/strings.idr+8
@@ -62,3 +62,11 @@ ltrim xs with (strM xs)
6262trim : String -> String
6363trim xs = ltrim (reverse (ltrim (reverse xs)))
6464
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