@@ -15,6 +15,15 @@ import Prelude.List
15import Prelude.Nat
15import Prelude.Nat
16import Decidable.Equality
16import Decidable.Equality
19+foldr1 : (a -> a -> a) -> List a -> a
21+foldr1 f (x::xs) = f x (foldr1 f xs)
24+foldl1 : (a -> a -> a) -> List a -> a
25+foldl1 f (x::xs) = foldl f x xs
18||| Appends two strings together.
27||| Appends two strings together.
20||| ```idris example
29||| ```idris example
@@ -247,15 +256,6 @@ lines' s = case dropWhile isNL s of
247lines : String -> List String
256lines : String -> List String
248lines s = map pack $ lines' $ unpack s
257lines s = map pack $ lines' $ unpack s
251−foldr1 : (a -> a -> a) -> List a -> a
253−foldr1 f (x::xs) = f x (foldr1 f xs)
256−foldl1 : (a -> a -> a) -> List a -> a
257−foldl1 f (x::xs) = foldl f x xs
259||| Joins the character lists by spaces into a single character list.
259||| Joins the character lists by spaces into a single character list.
261||| ```idris example
261||| ```idris example
@@ -263,12 +263,11 @@ foldl1 f (x::xs) = foldl f x xs
264unwords' : List (List Char) -> List Char
264unwords' : List (List Char) -> List Char
265unwords' [] = []
265unwords' [] = []
266−unwords' ws = assert_total (foldr1 addSpace ws)
266+unwords' ws = assert_total (foldr1 addSpace ws) where
268− addSpace : List Char -> List Char -> List Char
267+ addSpace : List Char -> List Char -> List Char
269− addSpace w s = w ++ (' ' :: s)
268+ addSpace w s = w ++ (' ' :: s)
271−||| Joins the strings by spaces into a single string.
270+||| Joins the strings by spaces into a single string.
273||| ```idris example
272||| ```idris example
274||| unwords ["A", "BC", "D", "E"]
273||| unwords ["A", "BC", "D", "E"]
@@ -276,6 +275,25 @@ unwords' ws = assert_total (foldr1 addSpace ws)
276unwords : List String -> String
275unwords : List String -> String
277unwords = pack . unwords' . map unpack
276unwords = pack . unwords' . map unpack
278+||| Joins the character lists by newlines into a single character list.
281+||| unlines' [['l','i','n','e'], ['l','i','n','e','2'], ['l','n','3'], ['D']]
283+unlines' : List (List Char) -> List Char
285+unlines' ls = assert_total (foldr1 addLine ls) where
286+ addLine : List Char -> List Char -> List Char
287+ addLine l s = l ++ ('\n' :: s)
289+||| Joins the strings by newlines into a single string.
292+||| unlines ["line", "line2", "ln3", "D"]
294+unlines : List String -> String
295+unlines = pack . unlines' . map unpack
279||| Returns the length of the string.
297||| Returns the length of the string.
281||| ```idris example
299||| ```idris example